Here is a program which uses GHC's FiniteMap and Andy Gill's monad library:

  varId :: String -> State (Int, FiniteMap String Int) Int
  varId s = do (n, e) <- get
            return n

BTW, the monad library defines:

  class (Monad m) => MonadState s m where
         get :: m s
         put :: s -> m () 

  instance MonadState s (State s) where ...

But hugs -98 (February 2000) complains with:

  ERROR "Infer.lhs" (line 162): Cannot justify constraints in explicitly typed binding
  *** Expression    : varId
  *** Type          : String -> State (Int,FiniteMap String Int) Int
  *** Given context : ()
  *** Constraints   : MonadState (Int,a) (State (Int,FiniteMap String Int))

which would be correct if I had not restricted the type, but clearly the
constraints can be satisfied (incidentally, I think "satisfy" is better than
"justify" in the error message text) with the signature I gave. For example,
this is enough to pass the type check:

  varId :: String -> State (Int, FiniteMap String Int) Int
  varId s = do (n, e::FiniteMap String Int) <- get
               return n

Hugs May 1999 exhibits the same problem... am I missing something?

-- 
Frank Atanassow, Dept. of Computer Science, Utrecht University
Padualaan 14, PO Box 80.089, 3508 TB Utrecht, Netherlands
Tel +31 (030) 253-1012, Fax +31 (030) 251-3791

Reply via email to