translating from fundeps into type families

Hi, Can I have some advice on translating the attached Test1.hs into type families? My attempt at doing so is in Test1a.hs, but firstly it requires FlexibleInstances where Test1.hs didn't, and secondly it fails because it can't infer the instance for Bar (Either Int Int) whereas the fundeps version had no problems there. (And yes, this is another cut down example of something I really want to do :-) Cheers, Ganesh

Ganesh Sittampalam:
Can I have some advice on translating the attached Test1.hs into type families? My attempt at doing so is in Test1a.hs, but firstly it requires FlexibleInstances where Test1.hs didn't, and secondly it fails because it can't infer the instance for Bar (Either Int Int) whereas the fundeps version had no problems there.
You need to write the instance as instance (b ~ TheFoo a, Foo a) => Bar (Either a b) where bar (Left a) = foo' a bar (Right b) = foo' (foo b :: a) Generally, you can't have type synonym families in instance heads. GHC should have complained about this despite your use of FlexibleInstances. (I'll fix that.) Unfortunately, the above will currently only go through if you specify UndecidableInstances. Nothing about it is undecidable, though, so the flag should not be required. Part of the trouble here is that, although we just completed a formal statement about the decidability of type checking for type families *without* taking context simplification into account <http://www.cse.unsw.edu.au/~chak/papers/SPCS08.html
, we are still lacking a formal statement about type checking for type families *with* context simplification.
My conjecture at the moment is that equalities of the form tv ~ F tv1 .. tvn where tv and tvi are distinct type variables should always be fine in class instance contexts and correspond to what is permitted for FDs. (However, previous experience with FDs and TFs clearly shows that any statements about decidability and completeness in this space are to be regarded with caution until they have been formalised rigorously.) I'll create a trac ticket with your example. Cheers, Manuel

2008/4/8, Manuel M T Chakravarty
You need to write the instance as
instance (b ~ TheFoo a, Foo a) => Bar (Either a b) where bar (Left a) = foo' a bar (Right b) = foo' (foo b :: a)
If you do that, the program compile, but res still raise a panic in GHC6.8.2 . Before you sent your solution, I also tried to do class (TheFoo a ~ b) => Foo a b where ... instance (Foo a b) => Bar (Either a b) where ... But it didn't compile, it seems to me both versions should have the same behaviour ? -- Jedaï

Chaddaï Fouché:
2008/4/8, Manuel M T Chakravarty
: You need to write the instance as
instance (b ~ TheFoo a, Foo a) => Bar (Either a b) where bar (Left a) = foo' a bar (Right b) = foo' (foo b :: a)
If you do that, the program compile, but res still raise a panic in GHC6.8.2 .
Before you sent your solution, I also tried to do
class (TheFoo a ~ b) => Foo a b where ...
instance (Foo a b) => Bar (Either a b) where ...
But it didn't compile, it seems to me both versions should have the same behaviour ?
6.8.2 has many bugs concerning type families that have been removed in the development version of GHC. Manuel
participants (3)
-
Chaddaï Fouché
-
Ganesh Sittampalam
-
Manuel M T Chakravarty