Typechecking Help

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Typechecking Help

Dominic Steinitz
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.






_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-cafe
Reply | Threaded
Open this post in threaded view
|

Re: Typechecking Help

Joel Reymont
I had this exact same issue when I swapped e and e1 by mistake.

Does your code work right without the type signature or does it just  
compile?

On Jan 2, 2006, at 8:59 AM, Dominic Steinitz wrote:

> 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.

--
http://wagerlabs.com/





_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-cafe
Reply | Threaded
Open this post in threaded view
|

Re: Typechecking Help

Dominic Steinitz
On Monday 02 Jan 2006 9:52 am, Joel Reymont wrote:
> I had this exact same issue when I swapped e and e1 by mistake.
>
> Does your code work right without the type signature or does it just
> compile?
>
It seems to work ok. I am able to parse an attribute certificate generated by
a different (java) implementation + the code passes various other tests.

I was curious as to why the type inferencer was giving me a result it then
wouldn't accept itself.

Dominic.


_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-cafe
Reply | Threaded
Open this post in threaded view
|

Re: Typechecking Help

Bulat Ziganshin
In reply to this post by Dominic Steinitz
Hello Dominic,

Monday, January 02, 2006, 11:59:53 AM, you wrote:

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

DS> But if I try to give it a type annotation of

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

you omited `forall` specifier, which, i think, makes the difference



--
Best regards,
 Bulat                            mailto:[hidden email]



_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-cafe
Reply | Threaded
Open this post in threaded view
|

Re: Typechecking Help

Dominic Steinitz
On Monday 02 Jan 2006 10:59 am, Bulat Ziganshin wrote:

> Hello Dominic,
>
> Monday, January 02, 2006, 11:59:53 AM, you wrote:
>
> *Codec.ASN1.BER>> :t choiceAux
> DS> choiceAux :: forall (m :: * -> *) e e1.
> DS>              (MonadState [Maybe Encoding] m,
> DS>               MonadState [Maybe Encoding] (StateT [Maybe Encoding] m),
> DS>               MonadError e (StateT [Maybe Encoding] m),
> DS>               MonadError e1 m) =>
> DS>              (TagPlicity, NamedType) -> Encoding -> m Defaulted
>
> DS> But if I try to give it a type annotation of
>
> DS> choiceAux :: (MonadState [Maybe Encoding] m,
> DS>               MonadState [Maybe Encoding] (StateT [Maybe Encoding] m),
> DS>               MonadError e (StateT [Maybe Encoding] m),
> DS>               MonadError e1 m) =>
> DS>              (TagPlicity, NamedType) -> Encoding -> m Defaulted
>
> you omited `forall` specifier, which, i think, makes the difference
Bulat,

I get the same error and furthermore I thought that any free type variables
were implicitly quantified, e.g.,

foobar :: Eq a => a -> a -> Bool
foobar x y = if x == y then True else False

*Main> :t foobar
foobar :: forall a. (Eq a) => a -> a -> Bool

Dominic.

_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-cafe