ninetynine-1.1.0: Ninety-Nine Haskell Problems
CopyrightCopyright (C) 2023 Yoo Chung
LicenseGPL-3.0-or-later
Maintainerdev@chungyc.org
Safe HaskellSafe-Inferred
LanguageGHC2021

Problems.Monads

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
Bounded Operator Source # 
Instance details

Defined in Problems.Monads

Enum Operator Source # 
Instance details

Defined in Problems.Monads

Show Operator Source # 
Instance details

Defined in Problems.Monads

Eq Operator Source # 
Instance details

Defined in Problems.Monads

data Element Source #

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

Instances

Instances details
Show Element Source # 
Instance details

Defined in Problems.Monads

Eq Element Source # 
Instance details

Defined in Problems.Monads

Methods

(==) :: Element -> Element -> Bool #

(/=) :: Element -> Element -> Bool #

parsePostfix :: String -> [Element] Source #

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"%"