[Haskell-beginners] Functional programming concepts

Daniel Fischer daniel.is.fischer at web.de
Wed Aug 27 11:37:11 EDT 2008


Am Mittwoch, 27. August 2008 16:42 schrieb Tillmann Rendel:
> Daniel Fischer wrote:
> > I don't have a CS degree either, so someone please correct me if I'm
> > wrong (or confirm if I'm right).
> > In Haskell, reducing a term to whnf (which e.g. seq is for) means
> > evaluating it far enough that its top level constructor is known (or it's
> > found to be bottom).
> > For some types like Int, that means complete evaluation, for others it's
> > far less.
> > A list is in whnf if you know whether it's bottom, [] or h:t, where you
> > might or might not know something about h and t.
> > A Maybe term is in whnf if you know if it's bottom, Nothing or Just
> > whatever. A function is in whnf if you know if it's bottom or \x -> rhs.
>
> That's correct, but be careful with your use of the term bottom. Most
> bottoms are never "found to be bottom", but instead, the program runs
> forever trying to find the top-level constructor.

Distinguish between findable and unfindable bottoms?
The difference in practice is clear, but is there also a theoretical 
difference?
>
> Another thing: you do not need seq to evaluate something to whnf, you
> can just pattern match on the top-level constructor instead.

Yes, what I wanted to convey was that seq doesn't fully evaluate its first 
argument but only reduces it to whnf.
Failed on that point :(

> seq is there for polymorphic values where you cannot pattern match
> since you don't know the possible constructors. Pattern matching is
> the main mechanism in Haskell to trigger evaluation.
>
>    Tillmann

Cheers,
Daniel



More information about the Beginners mailing list