learning to love laziness
Mark Tullsen
tullsen at galois.com
Thu Sep 25 13:59:37 EDT 2003
Haskell has lazy/lifted products and not true products. This "feature"
is considered by many to be an unfortunate aspect of Haskell. A 2-tuple
is just syntactic sugar for
data Tuple2 a b = Tuple2 a b
Maybe from seeing this, it's clearer why laws such as
x = (fst x,snd x)
do not hold. Neither does the following law hold
(uncurry . curry) f = f
which is unfortunate (for a language named after Haskell *Curry*).
To see why it doesn't hold, compare t1 and t2 in this program:
f (_,_) = 1
t1 = f undefined
t2 = (uncurry . curry) f undefined
- Mark
On Wednesday, September 24, 2003, at 02:07 PM, Norman Ramsey wrote:
> Consider the following Haskell function:
>
>> asPair x = (fst x, snd x)
>
> This function has type forall a b. (a, b) -> (a, b)
> and is almost equivalent to the identity function, except it
> can be used to make programs terminate that might otherwise fall
> into a black hole.
>
> My students are extremely mystified by such functions---and I can
> hardly
> blame them! Is there a good place to read about programming with lazy
> evaluation that will cover such functions and when to use them?
>
>
> Norman
> _______________________________________________
> Haskell mailing list
> Haskell at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell
>
More information about the Haskell
mailing list