[Haskell-cafe] Type infer

Marco Túlio Gontijo e Silva malebria at riseup.net
Mon Jan 22 13:09:20 EST 2007


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?

Thanks.

-- 
malebria
Marco Túlio Gontijo e Silva
Correio (MSN): malebria at riseup.net
Jabber (GTalk): malebria at jabber.org
Ekiga: malebria at ekiga.net
IRC: malebria at irc.freenode.net
     malebria at irc.oftc.org
Skype: marcotmarcot
Telefone: 33346720
Celular: 98116720
Endereço:
    Rua Paula Cândido, 257/201
    Gutierrez 30430-260
    Belo Horizonte/MG Brasil



More information about the Haskell-Cafe mailing list