Examples-0.1.0: Haskell code examples
Safe HaskellSafe-Inferred
LanguageHaskell2010

MyFreeMonad

Description

Free monads in Haskell are a powerful abstraction that allows for the creation of monadic structures without imposing additional constraints beyond those required by the monad definition. They are "free" in the sense that they are unrestricted, meaning they do not add any extra laws or structure beyond what is necessary for a monad.

A free monad satisfies all the Monad laws, but does not do any computation. It just builds up a nested series of contexts. The user who creates such a free monadic value is responsible for doing something with those nested contexts, so that the meaning of such a composition can be deferred until after the monadic value has been created.

Synopsis

Documentation

type ArithM = Free ArithF Source #

The free monad for the arithmetic language.

data ArithF x Source #

The functor for the arithmetic language.

Constructors

Add Int x 
Sub Int x 
Mul Int x 
Div Int x 

Instances

Instances details
Functor ArithF Source # 
Instance details

Defined in MyFreeMonad

Methods

fmap :: (a -> b) -> ArithF a -> ArithF b #

(<$) :: a -> ArithF b -> ArithF a #

Show x => Show (ArithF x) Source # 
Instance details

Defined in MyFreeMonad

Methods

showsPrec :: Int -> ArithF x -> ShowS #

show :: ArithF x -> String #

showList :: [ArithF x] -> ShowS #

evalArith :: Free ArithF Int -> Int Source #

Evaluate an arithmetic expression.