From babe62b2320dc7a937ef30437b59c7b7e73f3c37 Mon Sep 17 00:00:00 2001 From: Camil Staps Date: Sat, 24 Sep 2016 15:01:04 +0200 Subject: Added examples --- examples/fold.fusp | 14 ++++++++++++++ examples/monad.fusp | 14 ++++++++++++++ 2 files changed, 28 insertions(+) create mode 100644 examples/fold.fusp create mode 100644 examples/monad.fusp (limited to 'examples') 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); -- cgit v1.2.3