diff options
Diffstat (limited to 'examples/fold.fusp')
-rw-r--r-- | examples/fold.fusp | 14 |
1 files changed, 14 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; |