[Haskell-cafe] \_ -> not equivalent to const $
Luke Palmer
lrpalmer at gmail.com
Thu Jan 10 17:54:55 EST 2008
In attempting to devise a variant of cycle which did not keep its
argument alive (for the purpose of cycle [1::Int..]), I came across
this peculiar behavior:
import Debug.Trace
cycle' :: (a -> [b]) -> [b]
cycle' xs = xs undefined ++ cycle' xs
> take 20 $ cycle' (const $ 1:2:3:4:trace "x" 5:[])
[1,2,3,4,x
5,1,2,3,4,5,1,2,3,4,5,1,2,3,4,5]
Nuts. Oh, but wait:
> take 20 $ cycle' (\_ -> 1:2:3:4:trace "x" 5:[])
[1,2,3,4,x
5,1,2,3,4,x
5,1,2,3,4,x
5,1,2,3,4,x
5]
Hey, it worked!
Can someone explain what the heck is going on here?
Luke
More information about the Haskell-Cafe
mailing list