From: Camil Staps Date: Thu, 12 Mar 2015 11:25:11 +0000 (+0100) Subject: Working on takeWhile... X-Git-Url: https://git.martlubbers.net/?a=commitdiff_plain;h=0b0b2bb70f75161442c29fa83e0742e40fdeeb22;p=fp1415.git Working on takeWhile... --- diff --git a/week5/camil/Origami.icl b/week5/camil/Origami.icl index abd3cae..d844d2c 100644 --- a/week5/camil/Origami.icl +++ b/week5/camil/Origami.icl @@ -2,20 +2,21 @@ module Origami import StdEnv -Start = and +/*Start = and [ sum` [1 .. 5] == sum [1 .. 5] , prod` [1 .. 5] == prod [1 .. 5] , flatten` [[],[1],[1,2],[1,2,3]] == flatten [[],[1],[1,2],[1,2,3]] , reverse` [1 .. 5] == reverse [1 .. 5] , takeWhile` ((<>) 0) [1,2,3,0,4,5,6] == takeWhile ((<>) 0) [1,2,3,0,4,5,6] , maxList` [1 .. 5] == maxList [1 .. 5] - ] + ]*/ +Start = takeWhile` ((<>) 0) [1,2,3,0,4,5,6] sum` = foldr (+) 0 prod` = foldr (*) 1 flatten` = foldr (++) [] length` = foldl (\l e = l + 1) 0 reverse` = foldl (\xs x = [x:xs]) [] -takeWhile` = takeWhile +takeWhile` p = foldr (\x xs = if (p x) [x:xs] xs) [] maxList` [] = undef maxList` [x:xs] = foldr max x xs