diff options
author | Camil Staps | 2018-04-03 20:06:13 +0200 |
---|---|---|
committer | Camil Staps | 2018-04-03 20:06:13 +0200 |
commit | b5917471efab37e60949b380a24ecc35e2946203 (patch) | |
tree | e1359698e10bad08ac2c32e625d062ba8773b83f | |
parent | Beautify Makefile (diff) |
Extend examples
-rw-r--r-- | examples/fac.fusp | 6 | ||||
-rw-r--r-- | examples/int.fusp | 3 | ||||
-rw-r--r-- | examples/list.fusp | 5 |
3 files changed, 11 insertions, 3 deletions
diff --git a/examples/fac.fusp b/examples/fac.fusp index 38643d5..666967f 100644 --- a/examples/fac.fusp +++ b/examples/fac.fusp @@ -1,7 +1,7 @@ mul a b = code mul a b; -sub a b = code sub a b; +sub a b = code sub b a; fac 0 = 1; -fac n = mul n (fac (sub 1 n)); +fac n = mul n (fac (sub n 1)); -main = fac 5; +main = fac 4; diff --git a/examples/int.fusp b/examples/int.fusp index fe1e32d..b6ed1ac 100644 --- a/examples/int.fusp +++ b/examples/int.fusp @@ -8,3 +8,6 @@ gt a b = code gt a b; le a b = code le a b; lt a b = code lt a b; ne a b = code ne a b; + +pow _ 0 = 1; +pow x n = mul x (pow x (sub 1 n)); diff --git a/examples/list.fusp b/examples/list.fusp index b3f4ea5..340eb6d 100644 --- a/examples/list.fusp +++ b/examples/list.fusp @@ -33,3 +33,8 @@ map f [x:xs] = [f x:map f xs]; take _ [] = []; take 0 _ = []; take n [x:xs] = [x:take (sub 1 n) xs]; + +scan op r [] = [r]; +scan op r [a:x] = [r:scan op (op r a) x]; + +iterate f x = [x:iterate f (f x)]; |