Add remaining haskell book exercises
This commit is contained in:
7
Haskell-book/27/BottomExpression.hs
Normal file
7
Haskell-book/27/BottomExpression.hs
Normal file
@@ -0,0 +1,7 @@
|
||||
{-# LANGUAGE Strict #-}
|
||||
module BottomExpression where
|
||||
|
||||
!x = undefined
|
||||
y = "blah"
|
||||
main = do
|
||||
print $ snd $ seq x (x, y)
|
||||
20
Haskell-book/27/StrictList.hs
Normal file
20
Haskell-book/27/StrictList.hs
Normal file
@@ -0,0 +1,20 @@
|
||||
{-# LANGUAGE Strict #-}
|
||||
|
||||
module StrictList where
|
||||
|
||||
data List a =
|
||||
Nil
|
||||
| Cons ~a ~(List a)
|
||||
deriving (Show)
|
||||
|
||||
take' n _ | n <= 0 = Nil
|
||||
take' _ Nil = Nil
|
||||
take' n (Cons x xs) = (Cons x (take' (n - 1) xs))
|
||||
|
||||
map' _ Nil = Nil
|
||||
map' f (Cons x xs) = (Cons (f x) (map' f xs))
|
||||
|
||||
repeat' x = xs where xs = (Cons x xs)
|
||||
|
||||
main = do
|
||||
print $ take' 10 $ map' (+1) (repeat' 1)
|
||||
Reference in New Issue
Block a user