[Haskell-cafe] A type signature inferred by GHCi that is rejected when written explicitly

Alfonso Acosta alfonso.acosta at gmail.com
Mon Jul 7 11:30:21 EDT 2008


Hi Pablo,

On Mon, Jul 7, 2008 at 10:07 AM, Pablo Nogueira
<pablo at babel.ls.fi.upm.es> wrote:
> GHCi infers it has type (up to renaming):
>
> (From a1 (s (a1 x)) x,  Bifunctor s,  To  a2 (s (a2 y)) y) => (x -> y)
> -> a1 x -> a2 y
>
> But if I cut and paste the type into the code I get type errors:
>
>   Could not deduce (From a1 (s1 (a11 x)) x) ...
>    Could not deduce (From a11 (s1 (a11 x)) x, To a21 (s1 (a21 y)) y) ...
>    Could not deduce (From a1 (s1 (a11 x)) x) ...

I myselft  don't understand why GHCi doesn't accept the type it
infered as an explicit signature ... but your problem seems to be
caused by a lack of functional dependencies.

Redefining To and From as ..

class From a c x | a -> c where
    from :: a x -> c x

class To a c y | c -> a where
    to :: c y -> a y

... hushes GHCi. The question now is, of course, if the new
dependencies are too restrictive for your problem.


More information about the Haskell-Cafe mailing list