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
{-# LANGUAGE ScopedTypeVariables, MultiParamTypeClasses, FunctionalDependencies #-}
-- This loads fine, but Test1a.hs requires FlexibleInstances and then fails to
-- infer the necessary Bar instance
module Test1 where
class Foo a b | a -> b where
foo :: b -> a
foo' :: a -> Int
class Bar b where
bar :: b -> Int
instance Foo a b => Bar (Either a b) where
bar (Left a) = foo' a
bar (Right b) = foo' (foo b :: a)
instance Foo Int Int where
foo = id
foo' = id
val :: Either Int Int
val = Left 5
res :: Int
res = bar val
{-# LANGUAGE ScopedTypeVariables, TypeFamilies, FlexibleInstances #-}
module Test1a where
class Foo a where
type TheFoo a
foo :: TheFoo a -> a
foo' :: a -> Int
class Bar b where
bar :: b -> Int
instance Foo a => Bar (Either a (TheFoo a)) where
bar (Left a) = foo' a
bar (Right b) = foo' (foo b :: a)
instance Foo Int where
type TheFoo Int = Int
foo = id
foo' = id
val :: Either Int Int
val = Left 5
res :: Int
res = bar val
_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe