learning to love laziness
Iavor Diatchki
diatchki at cse.ogi.edu
Wed Sep 24 18:06:14 EDT 2003
hello,
Richard Nathan Linger wrote:
>
> On Wed, 24 Sep 2003, 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.
>>
>
>
> What is an example program that asPair rescues from nontermination?
'undefined' is a program that does not terminate.
'asPair undefined' is a program that terminates immediately (with a pair
containing two nonterminating components). unfortunatelu in haskell you
can tell the difference between those two:
test (x,y) = True
test undefind = undefined
test (asPair undefined) = True
it may be nice to have tuples unlifted in haskell (and in general
datatypes with a single constructor). this could be introduced in the
language by either changing the semantics of 'data' (prolly not too
nice) or by generalizing 'newtype' (and perhaps renaming it to 'record')
to handle more than one type. the semantics of such thing could be
just like now except that pattern matching on them is always lazy
(i.e.patterns have an implicit ~). then one could not tell the
difference between `undefined' and (undefined,undefined). well i guess
unless one used seq, but seq is also not very nice.
bye
iavor
--
==================================================
| Iavor S. Diatchki, Ph.D. student |
| Department of Computer Science and Engineering |
| School of OGI at OHSU |
| http://www.cse.ogi.edu/~diatchki |
==================================================
More information about the Haskell
mailing list