ivory-stdlib-0.1.0.0: Ivory standard library.

Safe HaskellNone

Ivory.Stdlib.Control

Synopsis

Documentation

ifte :: (IvoryStore a, IvoryZero (Stored a), GetAlloc eff ~ Scope s) => IBool -> Ivory eff a -> Ivory eff a -> Ivory eff aSource

when :: IBool -> Ivory eff () -> Ivory eff ()Source

unless :: IBool -> Ivory eff () -> Ivory eff ()Source

cond_ :: [Cond eff ()] -> Ivory eff ()Source

A multi-way if. This is useful for avoiding an explosion of nesting and parentheses in complex conditionals.

Instead of writing nested chains of ifs:

 ifte_ (x >? 100)
   (store result 10)
   (ifte_ (x >? 50)
     (store result 5)
     (ifte_ (x >? 0)
       (store result 1)
       (store result 0)))

You can write:

 cond_
   [ x >? 100 ==> store result 10
   , x >? 50  ==> store result 5
   , x >? 0   ==> store result 1
   , true     ==> store result 0
   ]

Note that ==> is non-associative and has precedence 0, so you will need parentheses to call functions with $ on the left-hand side:

 cond_ [ (f $ g x) ==> y ]

rather than:

 cond_ [ f $ g x ==> y ]

cond :: (IvoryStore a, IvoryZero (Stored a), GetAlloc eff ~ Scope s) => [Cond eff a] -> Ivory eff aSource

(==>) :: IBool -> Ivory eff a -> Cond eff aSource