Skip to content

Commit

Permalink
Reasoning for foldr
Browse files Browse the repository at this point in the history
  • Loading branch information
Anastasios Valtinos committed Oct 22, 2022
1 parent 2f401f3 commit cc1ad34
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
18 changes: 18 additions & 0 deletions Haskell Excercises & Code/Chapter27 - Nonstrictness/evaluEx.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
module EvEx where

-- Evaluation reasoning examples
1. const 1 undefined
2. const undefined 1
3. flip const undefined 1
4. flip const 1 undefined
5. const undefined undefined

6. foldr const 'z' ['a'..'e']
-- That reasoning i did was closer to foldl not foldr (read again and understood)
-- (foldr const 'z' ['a','b','c','d']) const 'e'
-- (((fodlr const 'z' ['a','b','c'] ) const 'd') const 'e')
-- ((((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
7. foldr (flip const) 'z' ['a'..'e']
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,11 @@ hypo = do
s <- getLine
case s of
"hi" -> print x
_ -> putStrLn "hello"
_ -> putStrLn "hello"

notGonnaHappenBru :: Int
notGonnaHappenBru =
let x = undefined
y = 2
z = (x `seq` y `seq` 10, 11)
in snd z

0 comments on commit cc1ad34

Please sign in to comment.