ninetynine-1.3.0: Ninety-Nine Haskell Problems
Copyright Copyright (C) 2023 Yoo Chung GPL-3.0-or-later dev@chungyc.org Safe-Inferred GHC2021

Description

Supporting definitions for monad problems.

Synopsis

# Documentation

data Operator Source #

Encodes an operator for a mathematical expression.

Constructors

 Negate Encodes negation. Equivalent to an unary minus. Unary operator. Add Encodes duplication. Makes another copy of its operand. Unary operator. Subtract Encodes subtraction. Binary operator. Multiply Encodes multiplication. Binary operator. Divide Encodes division. Equivalent to div. Binary operator. Modulo Encodes a modulo operator. Equivalent to mod. Binary operator.

#### Instances

Instances details
 Source # Instance detailsDefined in Problems.Monads Methods Source # Instance detailsDefined in Problems.Monads MethodsenumFrom :: Operator -> [Operator] #enumFromTo :: Operator -> Operator -> [Operator] # Source # Instance detailsDefined in Problems.Monads MethodsshowList :: [Operator] -> ShowS # Source # Instance detailsDefined in Problems.Monads Methods

data Element Source #

A single element within a mathematical expression. A list of these elements comprises an expression in postfix notation.

Constructors

 Operator Operator Operand Integer

#### Instances

Instances details
 Source # Instance detailsDefined in Problems.Monads MethodsshowList :: [Element] -> ShowS # Source # Instance detailsDefined in Problems.Monads Methods(==) :: Element -> Element -> Bool #(/=) :: Element -> Element -> Bool #

Parses a string containing a mathematical expression in postfix notation. This can make it easier to write down an expression in a more conventional form.

For example,

>>> parsePostfix "3 4 2 - *"
[Operand 3,Operand 4,Operand 2,Operator Subtract,Operator Multiply]


The operators are encoded as follows:

OperatorString
Negate"negate"
Add"+"
Subtract"-"
Multiply"*"
Divide"/"
Modulo"%"