[Haskell-beginners] A question about an infinite type
Lorenzo Bolla
lbolla at gmail.com
Thu Mar 22 10:53:39 CET 2012
You can find your answer here:
http://en.wikibooks.org/wiki/Haskell/YAHT/Type_advanced
On Tue, Feb 28, 2012 at 12:52 PM, Costello, Roger L. <costello at mitre.org>wrote:
> Hi Folks,
>
> Here is an interesting phenomena:
>
> let f = (\x y -> x y x)
>
> let p = (\x y -> 1)
>
> Now let's evaluate f p 1
>
> f p 1 = (\x y -> x y x) p 1 -- by replacing f with its
> definition
>
> = p 1 p -- by substituting
> x with p and y with 1
>
> = (\x y -> 1) 1 p -- by replacing the first p
> with its definition
>
> = 1 -- the function
> returns 1 regardless of its arguments
>
> However, Haskell will not proceed with that evaluation because it will
> first determine the
>
> type signature of f and judge it to be an infinite type.
>
> Conversely, if f is omitted and this expression
>
> p 1 p
>
> is evaluated then the result 1 is generated.
>
> Why does f p 1 (which evaluates to p 1 p) fail whereas p 1 p succeeds?
>
> What lesson should I learn from this example?
>
> /Roger
>
> _______________________________________________
> Beginners mailing list
> Beginners at haskell.org
> http://www.haskell.org/mailman/listinfo/beginners
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/beginners/attachments/20120322/e53474bc/attachment.htm>
More information about the Beginners
mailing list