r/haskellquestions • • Sep 27 '17

Why does not get evaluate?

Hi all

I have following code snippet:

*Main Lib> let myList = [1, 2, id 1] :: [Integer]
*Main Lib> let myList' = myList ++ undefined
*Main Lib> :sprint myList'
myList' = _

Why does the myList does not get evaluated?

And this too:

*Main Lib> x = 45
*Main Lib> :sprint x
x = _

Let's consider the first example. When I write *Main Lib> myList ++ undefined then it is an application and it gets evaluated.

When I write let myList' = myList ++ undefined is a lambda abstraction, that why it does not get evaluated, right?

Thanks

0 Upvotes

5 comments sorted by

1

u/quiteamess Sep 27 '17

"Parallel and Concurrent programming in Haskell" has a nice chapter on evaluation. FPComplete also wrote an article on evaluation and strictness.

1

u/ElvishJerricco Sep 27 '17

I may be misremembering “Parallel and Concurrent Haskell,” but i don’t believe either of those resources actually touches on the OP’s problem

1

u/quiteamess Sep 27 '17

I may have misunderstood OPs question. I thought it was a general question on how the runtime works and when thunks are evaluated. While "Parallel and concurrent programming in Haskell" is not a book about this topic it has a nice chapter on evaluation.

1

u/Noughtmare Sep 27 '17 edited Sep 27 '17

When you assign a value to a variable in ghci, for example using a let binding, nothing gets evaluated. When you put myList ++ undefined in ghci, it automatically interprets it as print (myList ++ undefined) and starts printing, to be able to print it needs to evaluate myList and it also tries to evaluate undefined, but that throws an error.