[Haskell-cafe] Problem trying to get class Bounded to work

Brian Hulley brianh at metamilk.com
Mon May 22 20:00:34 EDT 2006

Chris Kuklewicz wrote:
> See " Declaration type signatures" in the manual:
> http://haskell.org/ghc/docs/6.4.2/html/users_guide/type-extensions.html#decl-type-sigs
> At the moment, the "i" in the type declaration and in the body are
> not the same "i".
> To get the "i" from the type declaration for createMonoMultiFont into
> the scope
> of the definition, the trick is to add the otherwise
> useless/forbidden "forall i m." to the type declaration:
> createMonoMultiFont
>     :: forall i m.(MonadException m, Enum i, Bounded i)
>     => [(i, Font, Colour)] -> m (MonoMultiFont i)
> createMonoMultiFont elements =
>     liftIO . block $ do
>          mmfRaw <- duma_MonoMultiFont_create (fromEnum (maxBound::i))
>          mmfPtr <- newForeignPtr duma_MonoMultiFont_Release mmfRaw
>          return $ MonoMultiFont mmfPtr
> The above is now accepted by ghci on my GHC 6.4.1 installation on OS
> X.

Thanks - I'd completely forgotten about the need to add an explicit forall, 
because although I read the section a while ago, the need for the forall got 
clouded over in my mind by the fact that the forall is unnecessary for the 
type signature itself, so the need for the forall seems to be just a good 
way to slot this extra functionality into the language while remaining 
backwards compatible with H98.

I wonder if Haskell' will automatically make type variables scope over the 
function body (without an explicit forall)? Is there any reason why they 
shouldn't always do so?

Thanks again,

More information about the Haskell-Cafe mailing list