Phil Writes:
|However, for the extended type system that allows polymorphism in
|recursion, this is no longer the case -- my thanks to Lennart
|Augustsson for pointing this out. The counter-example (similar
|to one of Mark's) is:
|
| g :: a -> Bool
| g x = g [x]
|
|This function is silly, as it never terminates, but there are less
|silly examples; see below. Note that the trick for translating
|polymorphic recursion into type classes (as described by Konstantin) no
|longer works here. The closest one can come is
|
| class G a where
| g :: a -> Bool
| g x = g [x]
|
| instance G Int where
| instance G [Int] where
| instance G [[Int]] where
| ...
|
|which requires an infinite number of instance declarations.
Can't this be written as follows?
instance G Int where
instance (G a) => G [a] where
Now, this is still an infinite number of instances, though not
declarations, so the point still holds that it can't be monomorphized.
--Joe
Joseph H. Fasel
Los Alamos National Laboratory