From b5917471efab37e60949b380a24ecc35e2946203 Mon Sep 17 00:00:00 2001 From: Camil Staps Date: Tue, 3 Apr 2018 20:06:13 +0200 Subject: Extend examples --- examples/fac.fusp | 6 +++--- examples/int.fusp | 3 +++ examples/list.fusp | 5 +++++ 3 files changed, 11 insertions(+), 3 deletions(-) (limited to 'examples') 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)]; -- cgit v1.2.3