Implementing type classes in Hugs - question

Alastair Reid alastair@reid-consulting-uk.ltd.uk
27 Dec 2002 09:47:22 +0000


> [...]
> My question is: why doesn't Hugs partially evaluate the inc99 SC
> (before code generation) to yield the following definition?
> [...]
> Is it simply that this kind of specialization was never implemented
> in Hugs?  Or is the above transformation not as straightfoward as it
> seems?

Gofer lacks polymorphic recursion so any polymorphic programs can be
transformed into an equivaluent finite monomorphic programs using the
partial evaluation technique you cite.

Haskell 98 provides polymorphic recursion which means that the same
transformation yields an infinite result (or doesn't terminate
depending on your point of view).  For example, this program is
legal in H98 but not in Gofer.

  main = print (f True)

  f :: a -> a
  f x = head (f [x])

Try transforming it to a monomorphic program and you'll find yourself
with an infinite set of 'f' functions.

--
Alastair Reid                 alastair@reid-consulting-uk.ltd.uk  
Reid Consulting (UK) Limited  http://www.reid-consulting-uk.ltd.uk/alastair/