[Haskell-cafe] Typechecking Help

Dominic Steinitz dominic.steinitz at blueyonder.co.uk
Mon Jan 2 03:59:53 EST 2006


I have a function which, without a type annotation, types as:

*Codec.ASN1.BER> :t choiceAux
choiceAux :: forall (m :: * -> *) e e1.
             (MonadState [Maybe Encoding] m,
              MonadState [Maybe Encoding] (StateT [Maybe Encoding] m),
              MonadError e (StateT [Maybe Encoding] m),
              MonadError e1 m) =>
             (TagPlicity, NamedType) -> Encoding -> m Defaulted

But if I try to give it a type annotation of

choiceAux :: (MonadState [Maybe Encoding] m,
              MonadState [Maybe Encoding] (StateT [Maybe Encoding] m),
              MonadError e (StateT [Maybe Encoding] m),
              MonadError e1 m) =>
             (TagPlicity, NamedType) -> Encoding -> m Defaulted

I get 

Codec/ASN1/BER.hs:66:0:
    Quantified type variable `e1' is unified with another quantified type 
variable e
    When trying to generalise the type inferred for `choiceAux'
      Signature type:     forall (m :: * -> *) e e1.
                          (MonadState [Maybe Encoding] m,
                           MonadState [Maybe Encoding] (StateT [Maybe 
Encoding] m),
                           MonadError e (StateT [Maybe Encoding] m),
                           MonadError e1 m) =>
                          (TagPlicity, NamedType) -> Encoding -> m Defaulted
      Type to generalise: (TagPlicity, NamedType) -> Encoding -> m Defaulted
    In the type signature for `choiceAux'
    When generalising the type(s) for tc, choiceAux, k

Changing e1 to e makes it typecheck. 

1. Can anyone explain why the typechecker rejects the type it had inferred for 
itself?

2. I thought StateT guaranteed that the lifted monad was a state monad so why 
is the typechecker adding MonadState ... (StateT ... ) to the list of 
constraints? Ditto for MonadError ... (StateT ... )?

Thanks, Dominic.

PS

What I thought I was going to get was 

choiceAux :: forall (m :: * -> *) e.
             (MonadError e m, MonadState [Maybe Encoding] m) =>
             (TagPlicity, NamedType) -> Encoding -> m Defaulted

and this is what I have now specified.








More information about the Haskell-Cafe mailing list