[Haskell-beginners] Functional programming concepts

Tillmann Rendel rendel at daimi.au.dk
Wed Aug 27 10:42:45 EDT 2008


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.

Another thing: you do not need seq to evaluate something to whnf, you 
can just pattern match on the top-level constructor instead. 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


More information about the Beginners mailing list