[Haskell-cafe] Type infer

Bryan Donlan bd.haskell at uguu.us
Wed Jan 24 20:36:57 EST 2007


Marco Túlio Gontijo e Silva wrote:
> Hello,
> 
> I'm trying to define a partition__ function that is like
> Data.Set.partition, but use State Monad:
> 
>> import Data.Set
>> import Control.Monad.State
> 
>> partition__ f =
>>     do
>>     snapshot <- get
>>     let
>>         (firsts, rest) = Set.partition f snapshot
>>     put rest
>>     return firsts
> 
> When I try to infer it's type in ghci I got:
> 
> $ ghci
>    ___         ___ _
>   / _ \ /\  /\/ __(_)
>  / /_\// /_/ / /  | |      GHC Interactive, version 6.6, for Haskell 98.
> / /_\\/ __  / /___| |      http://www.haskell.org/ghc/
> \____/\/ /_/\____/|_|      Type :? for help.
> 
> Loading package base ... linking ... done.
> Prelude> :load partition.hs
> [1 of 1] Compiling Main             ( partition.hs, interpreted )
> Ok, modules loaded: Main.
> *Main> :type partition__
> partition__ :: (MonadState (Set a) t, Ord a) => (a -> Bool) -> t (Set a)
> 
> Ok, then I add
> 
>> partition__ :: (MonadState (Set a) t, Ord a) => (a -> Bool) -> t (Set
> a)
> 
> to the file and then:
> 
> *Main> :reload
> [1 of 1] Compiling Main             ( partition.hs, interpreted )
> 
> partition.hs:4:0:
>     Non type-variable argument in the constraint: MonadState (Set a) t
>     (Use -fglasgow-exts to permit this)
>     In the type signature for `partition__':
>       partition__ :: (MonadState (Set a) t, Ord a) =>
>                      (a -> Bool) -> t (Set a)
> Failed, modules loaded: none.
> 
> Why do I need glasgow-exts to specify a type infered by GHCi without
> -fglasgow-exts?

I'd imagine the check that you're using -fglasgow-exts is performed when 
parsing type signatures from the parser. When you allow GHC to infer the 
type, it's pulling that from Control.Monad.State, which was compiled 
with -fglasgow-exts - it's simply not checking that all the types you 
might infer from there are legal without -fglasgow-exts.


More information about the Haskell-Cafe mailing list