> One modest extension we could make to the Haskell type system is
>
> to permit polymorphic recursion if
> a type signature is provided
I'm absolutely for this suggestion (especially since hbc already has
it :-). My reason for this is that it is already possible to do
this in Haskell! It's just very tedious. Why not make it easy?
There is no need to worry (more than before) if it adds any
complexity to the language since it can already be done (as I'll
explain below).
How is it done now?
Let's take Simon's example:
data Foo a = A | B (Foo [a])
-- f :: Foo a -> ()
f A = ()
f (B thing) = f thing
OK, put it in a module M, import another module M'.
Change the recursive call to f into f' (imported from M').
module M(f, Foo) where
import M' (f')
data Foo a = A | B (Foo [a])
f :: Foo a -> ()
f A = ()
f (B thing) = f' thing
To compile this we need the interface file for M'. We write this by
hand (perfectly permissible in Haskell, perhaps even preferable?).
interface M' where
import M(Foo)
data Foo
f' :: Foo a -> ()
Now M can be compiled, and if we automatically generate an interface we get
interface M where
data Foo
f :: Foo a -> ()
And now we can write (and compile) M'.
module M' where
import M(Foo, f)
f' :: Foo a -> ()
f' A = ()
f' (B thing) = f thing
Et Voila!
The trick is the mutual recursion to get it to trust a handwritten
interface file.
To summarize. Let's adopt Simon's proposal. It just makes an
already existing feature easy to use.
-- Lennart