[Haskell-beginners] Lazy evaluation, trying to find out when its done

Lai Boon Hui laiboonh at gmail.com
Sun Oct 9 02:27:22 UTC 2016


Hi all,

I understand that the take method will evaluate the value inside the cons
cell whereas length will just evaluate the spine or structure of the list

λ> let y = "abc"
Prelude|
y :: [Char]
λ> :sprint y
y = _
λ> take 1 y
"a"
it :: [Char]
λ> :sprint y
y = 'a' : _
λ>

Well and good but why doesn't the same work on a list of Nums??

λ> let x = [1,2,3]
Prelude|
x :: Num t => [t]
λ> :sprint x
x = _
λ> take 1 x
[1]
it :: Num a => [a]
λ> :sprint x
x = _
λ>

I expected to see x = 1 : _

-- 
Best Regards,
Boon Hui
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/beginners/attachments/20161009/7f08152b/attachment.html>


More information about the Beginners mailing list