Working on takeWhile...
authorCamil Staps <info@camilstaps.nl>
Thu, 12 Mar 2015 11:25:11 +0000 (12:25 +0100)
committerCamil Staps <info@camilstaps.nl>
Thu, 12 Mar 2015 11:25:11 +0000 (12:25 +0100)
week5/camil/Origami.icl

index abd3cae..d844d2c 100644 (file)
@@ -2,20 +2,21 @@ module Origami
 \r
 import StdEnv\r
 \r
-Start                  = and\r
+/*Start                        = and\r
                                  [ sum`       [1 .. 5]                 == sum       [1 .. 5]\r
                                  , prod`      [1 .. 5]                 == prod      [1 .. 5]\r
                                  , flatten`   [[],[1],[1,2],[1,2,3]]   == flatten   [[],[1],[1,2],[1,2,3]]\r
                                  , reverse`   [1 .. 5]                 == reverse   [1 .. 5]\r
                                  , takeWhile` ((<>) 0) [1,2,3,0,4,5,6] == takeWhile ((<>) 0) [1,2,3,0,4,5,6]\r
                                  , maxList`   [1 .. 5]                 == maxList   [1 .. 5]\r
-                                 ]\r
+                                 ]*/\r
+Start = takeWhile` ((<>) 0) [1,2,3,0,4,5,6]\r
 \r
 sum`                   = foldr (+) 0\r
 prod`                  = foldr (*) 1\r
 flatten`               = foldr (++) []\r
 length`                        = foldl (\l e = l + 1) 0\r
 reverse`               = foldl (\xs x = [x:xs]) []\r
-takeWhile`             = takeWhile\r
+takeWhile` p           = foldr (\x xs = if (p x) [x:xs] xs) []\r
 maxList` []            = undef\r
 maxList` [x:xs]                = foldr max x xs\r