[EMAIL PROTECTED] asks:

|  Is it possible to force evaluation of an
|  expression resulting in a list to normal
|  form? (Using {-#STRICT#-} seems not to
|  be the right way.)

In principle, yes, although it depends to a certain degree
on what you consider to be `normal form'.  If you just want
to evaluate a list to the point where you can distinguish
between empty and non-empty lists, then you just need to
apply a function like:

>  whnfList xs = case xs of []     -> xs
>                           (y:ys) -> xs

If, however, you wanted to force the evaluation of the spine
of the list, then you might use a function like:

>  spineList   :: [a] -> [a]
>  spineList xs = foldr (\y ys -> ys) xs xs

To see how this works, you could just expand the foldr into
a local `loop':

>  spineList xs = h xs
>   where h []     = xs
>         h (y:ys) = h ys

i.e. the function h works its way to the end of the list and then
returns the original list (now evaluated) as its result.

[In the same spririt, whnfList could be defined:

> whnfList xs = foldr (\y ys -> xs) xs xs

Some may think me crazy for suggesting this, but it actually generalizes
rather nicely to many other data types...]

Perhaps you had some other idea of `normal form' in mind?  For example,
maybe you wanted to evaluate the elements of the list as well?  In that
case, you will need to extend the tricks I've show here a little further.
At each stage, the types of the objects involved are important in determining
how to evaluate them; general functions for reducing objects to different
kinds of normal form can be implemented using type classes.

Hope that helps!
Mark

PS.  A less elegant, but commonly used (and perhaps faster-to-write) hack
to force hyperstrict evaluation uses a function along the lines of:

      force  :: Eq a => a -> a
      force x = if x==x then x else x

However, this is a little bit wasteful and restricted to equality types (not
to mention that it also relies on assumptions about how individual equality
functions are defined).

Reply via email to