[Haskell-cafe] Re: Wikipedia on first-class object

Chaddaï Fouché chaddai.fouche at gmail.com
Sun Dec 30 16:25:19 EST 2007

2007/12/30, Chaddaï Fouché <chaddai.fouche at gmail.com>:
> 2007/12/30, Cristian Baboi <cristian.baboi at gmail.com>:
> > A simple question:
> >
> > Can you write the value of x to a file where x = (1:x) ?
> Yes, but you'll have to write it yourself, because Haskell can't
> decide by itself that this value is infinite and try to print it with
> a recursive definition, if it could do that, it could decide the
> halting problem and that's not possible.

Sorry, I'll try to be more precise since Cristian is pretty sticky
with details when he can use them in its sense...

In the particular case of x = (1:x), it can be detected that the
structure is circular in memory and so infinite, but in the general
case (for example if you replace (1:x) by (1:f x)) it can't be decided
if the value is finite or infinite. You can't do a printer that do
what you want in Haskell itself but you could probably do it with a VM
or with compiler support, but it would be extremely tricky, also it
would _always_ use the "running" form, even if this form isn't the
optimal for storage (for example a filter of a huge list that results
in an empty list would take enormously more place than with a normal


More information about the Haskell-Cafe mailing list