See "7.4.10.3 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. -- Chris Brian Hulley wrote: > Hi - > I've got the following function which doesn't compile: > > createMonoMultiFont > :: (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 problem is that ghc complains that there is no instance for Bounded > i even though I've written "Bounded i" in the type declaration for the > function. > > I was expecting that I could use the same type variables in the function > body as in the type signature so that I could use maxBound::i to find > the max bound of whatever type is instantiated to i. > > What am I doing wrong here, and is it possible to create such a function? > > Thanks, Brian. > _______________________________________________ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe