summaryrefslogtreecommitdiff
path: root/Haskell-book/27/StrictList.hs
blob: f75bb058e03d22eab241c4fa1c0fea96850acfc0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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)