diff options
-rw-r--r-- | examples/fold.fusp | 14 | ||||
-rw-r--r-- | examples/monad.fusp | 14 |
2 files changed, 28 insertions, 0 deletions
diff --git a/examples/fold.fusp b/examples/fold.fusp new file mode 100644 index 0000000..0d38cdc --- /dev/null +++ b/examples/fold.fusp @@ -0,0 +1,14 @@ +mul a b = code mul a b; +sub a b = code sub a b; + +foldr op r [] = r; +foldr op r [a:x] = op a (foldr op r x); + +prod = foldr mul 1; + +faclist 0 = []; +faclist n = [n:faclist (sub 1 n)]; + +fac n = prod (faclist n); + +main = fac 12; diff --git a/examples/monad.fusp b/examples/monad.fusp new file mode 100644 index 0000000..b71e1c1 --- /dev/null +++ b/examples/monad.fusp @@ -0,0 +1,14 @@ +left x = (x, 0); +right x = (0, x); + +pure = right; +bind (l,0) f = (l,0); +bind (0,r) f = f r; + +mul a b = code mul a b; +sub a b = code sub a b; + +mulM x y = right (mul x y); +subM x y = right (sub x y); + +main = bind (bind (pure 5) (mulM 10)) (subM 10); |