Skip to content

Commit

Permalink
Understanding strictness and bottom
Browse files Browse the repository at this point in the history
  • Loading branch information
Anastasios Valtinos committed Oct 23, 2022
1 parent eb332a5 commit 5e00bab
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
17 changes: 17 additions & 0 deletions Haskell Excercises & Code/Chapter27 - Nonstrictness/chapterEx.hs
Original file line number Diff line number Diff line change
@@ -1,2 +1,19 @@
{-# LANGUAGE Strict #-}
-- this is an extension to enable strictness

module ChaptEx 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)
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ module EvEx where
-- ((((foldr const 'z' ['a','b']) const 'c' ) const 'd') const 'e')
-- (((((foldr const 'z' ['a']) const 'b') const 'c') const 'd') const 'e'
-- ((((((foldr const 'z' [] ) const 'a' ) const 'b') const 'c') const 'd') const 'e')
-- Wrong reasoning
-- Wrong reasoning but answer = 'a'
7. foldr (flip const) 'z' ['a'..'e']

0 comments on commit 5e00bab

Please sign in to comment.