The dreaded M-R

Ben Rudiak-Gould Benjamin.Rudiak-Gould at cl.cam.ac.uk
Tue Jan 31 16:13:29 EST 2006


John Meacham wrote:
> interestingly enough, the monomorphism restriction in jhc actually
> should apply to all polymorphic values, independently of the type class
> system.
> 
> x :: a 
> x = x 
> 
> will transform into something that takes a type parameter and is hence
> not shared.

Interesting. I'd been wondering how you dealt with this case, and now it 
turns out that you don't. :-)

> I doubt this will cause a problem in practice since there
> arn't really any useful values of type forall a . a other than bottom.

It could become an issue with something like

   churchNumerals :: [(a -> a) -> (a -> a)]
   churchNumerals = ...

Maybe you could use a worker-wrapper transformation.

   churchNumerals' :: [(T -> T) -> (T -> T)]
   churchNumerals' = ...

   churchNumerals :: [(a -> a) -> (a -> a)]
   churchNumerals = /\ a . unsafeCoerce churchNumerals'

The unsafeCoerce is scary, but it feels right to me. There is something 
genuinely unsavory about this kind of sharing, in Haskell or any other ML 
dialect. At least here it's out in the open.

-- Ben



More information about the Haskell-prime mailing list