\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
-Start = takeWhile` ((<>) 0) [1,2,3,0,4,5,6]\r
+ ]\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` p = foldr (\x xs = if (p x) [x:xs] xs) []\r
+takeWhile` _ [] = []\r
+takeWhile` p xs\r
+ | p (xs!!0) = take (maxList [i \\ i <- [0..length xs-1] | foldr (&&) True [p (xs!!j) \\ j <- [0..i]]] + 1) xs\r
+ | otherwise = []\r
maxList` [] = undef\r
maxList` [x:xs] = foldr max x xs\r