[Haskell-cafe] The values of infinite lists

Robert Dockins robdockins at fastmail.fm
Wed May 10 13:05:59 EDT 2006


On Wednesday 10 May 2006 12:30 pm, Brian Hulley wrote:
> Bjorn Lisper wrote:
> > Nontermination is not
> > the precisely the same as _|_. Only certain kinds of nontermination
> > can be modeled by _|_ in a non-strict language.
>
> What kinds of non-termination are *not* modelled by _|_ in Haskell?

Non-termination that is "doing something".

For example consider:

] ones = 1 : ones

If I try to take its length, I get _|_.  So:

] main = print (length ones)

Will churn my CPU forever without producing any output.

However, if I print each item sequentially:

] main = mapM print ones

I'll get a never-ending stream of '1' on my console.  This is not the same as 
bottom because it's "doing something".

Now, obviously this definition is pretty imprecise, but maybe it helps you get 
the idea.  Now for the corner cases.  What about:

] main = sequence_ repeat (return ())

?  I'd personally say it is _not_ bottom.  Even though "return ()" is a 
completely useless action, I'm inclined to say its "doing something" in some 
theoretical sense (mostly because I think of _|_ as being a property of the 
functional part of Haskell).


More information about the Haskell-Cafe mailing list