Scrapbook-0.4.0: code examples
Copyright© Frank Jung 2023
LicenseGPL-3
Safe HaskellSafe-Inferred
LanguageHaskell2010

MyFreeMonad

Description

The code was originally provided by ChatGPT. It had to be modified to compile. I added tests.

Synopsis

Documentation

type ArithM = Free ArithF Source #

Arithmetic free monad.

data ArithF x Source #

Arithmetic functor.

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 #

Given Arithmetic free monad, return its value.

example :: Int -> ArithM Int Source #

A simple example on how to use DSL:

example 0 = ((((0+10)*2)-10)/2) == 5

Get back the integer value with:

evalArith (example 0)

example' :: Int -> ArithM Int Source #

Another example on how to use this DSL: