2007/12/30, Chaddaï Fouché <[EMAIL PROTECTED]>:
> 2007/12/30, Cristian Baboi <[EMAIL PROTECTED]>:
> > 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
printer).

-- 
Jedaï
_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to