argument permutation and fundeps

C T McBride C T McBride <C.T.McBride@durham.ac.uk>
Thu, 10 May 2001 17:13:34 +0100 (BST)


> C T McBride wrote:
> 
> > Hi
> >
> > This is a long message, containing a program which makes heavy use of
> > type classes with functional dependencies, and a query about how the
> > typechecker treats them. It might be a bit of an effort, but I'd be
> > grateful for any comment and advice more experienced Haskellers can
> > spare the time to give me. Er, this ain't no undergrad homework...

Jeffrey R. Lewis:
>
> Without delving too deeply into your example, it looks like you've bumped
> into a known bug in Hugs implementation of functional dependencies.  You
> should try GHCI if you can - it doesn't suffer from this bug.

Thanks for the tip! Our local Haskell supremo has pointed me to a version
I can run, and that has improved the situation... a bit.

Now I get

  Perm> permArg (FS (S O) (FO O),(FO O,()))

  No instance for `Show ((r -> s -> s) -> s -> r -> s)'

Obviously, there's no Show method, but I was expecting a more general
type. But if I tell it the right answer, it believes me

  Perm> permArg (FS (S O) (FO O),(FO O,()))
        :: (a -> b -> c) -> b -> a -> c

  No instance for `Show ((a -> b -> t) -> b -> a -> t)'

The main thing is that I can permute a function correctly, without needing
an explicit signature:

  Perm> permArg (FS (S (S O)) (FO (S O)),(FS (S O) (FO O),(FO O,())))
        foldl

  No instance for `Show ([b] -> (t -> b -> t) -> t -> t)'

Still, those too-specific inferred types are disturbing me a little

  Perm> permArg (FS (S (S O)) (FO (S O)),(FS (S O) (FO O),(FO O,())))

  No instance for `Show ((r -> s -> s -> s) -> s -> r -> s -> s)'

The above examples show that my code works with the generality it needs
to. Is there some `defaulting' mechanism at work here for the inferred
types making all those s's the same?

But this is definitely progress!

Thanks

Conor