{- how to define a function -} square :: R -> R square (x) = x * x {- guarded function -} abs :: R -> R abs(x) = x if x >= 0 or -x {- functions of multiple variables -} max :: R X R -> R max (x,y) = x if x >= y or y {- this is also a function -} signal :: R -> Fig signal (r) = join(color(circ(r),Red),rect(r*1.6,r*0.4)) {- {- sets defined by enumeration -} set Bool = {False, True} not :: Bool -> Bool not (b) = False if b == True or True and :: Bool X Bool -> Bool and (b1,b2) = False if b1 == False or b2 {--} {- sets defined by predicate -} set N = { n in Z | n >= 0 } {- "subtyping" -} succ :: N -> Z succ (n) = n + 1 {- even worse -} pred :: N -> N pred (n) = n - 1 {- foo :: N -> NPos foo (n) = 0 + 0 -} {- set NPos = { n in N | n /= 0 } predT :: NPos -> N predT (n) = n - 1 {- sequences and recursion -} length :: R* -> N length (l) = 0 if l == [] or 1 + length(rest(l)) set RSeqNoE = { l in R* | length(l) > 0 } head :: RSeqNoE -> R head (l) = first(l) -} {- a sequence of Figures is an animation -} sqMove :: Fig X Z X Z -> Fig* sqMove (f,start,end) = [] if start > end or move(f,(start,square(start))) : sqMove(f,start+1,end) {- {- overlapping conditions -} foo :: Z -> Z foo (x) = 1 if x > 2 or 2 if x > 1 or x -} {- this is not the flag of Taiwan -} flag :: R -> Fig flag (x) = scale(join(color(rect(10,6),Red) ,move(join(color(rect(5,3),Blue) ,circ(0.8)) ,(-2.5,1.5))),x) -}