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

Tom Murphy amindfv at gmail.com
Sun Oct 9 04:34:31 UTC 2016


Maybe this will help answer some questions and raise others:

 .  let x = [1,2,3]
 .  take 1 x
[1]
 .  :sprint x
x = _
 .  let x = [1,2,3] :: [Int]
 .  take 1 x
[1]
 .  :sprint x
x = [1,2,3]

Tom


On Sun, Oct 09, 2016 at 10:27:22AM +0800, Lai Boon Hui wrote:
> 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

> _______________________________________________
> Beginners mailing list
> Beginners at haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners



More information about the Beginners mailing list