The problem is that your instances overlap:
instance (Fun f' a' b) => Fun (a -> f') a' (a -> b) where
instance Fun (Kwarg name t -> b) (Kwarg name t) b
-- this is actually a special case of the above, with a ~ a' ~ KWarg name t
It becomes clearer if we replace the functional dependence (which is IMO, as a rule, it’s a little difficult to reason) with an equivalent type family:
{-
class Fun f a where
type FRes f a :: *
runFun :: f -> a -> FRes f a
instance Fun f' a' => Fun (a -> f') a' where
type FRes (a -> f') a' = a -> FRes f' a'
runFun f a' = \a -> runFun (f a) a'
instance Fun (Kwarg name t -> b) (Kwarg name t) where
type FRes (Kwarg name t -> b) (Kwarg name t) = b
runFun = id
In this case, the compiler message is pretty clear:
Conflicting family instance declarations:
FRes (a -> f') a' = a -> FRes f' a'
-- Defined at /tmp/wtmpf-file10498.hs:20:8
FRes (Kwarg name t -> b) (Kwarg name t) = b
-- Defined at /tmp/wtmpf-file10498.hs:24:8
|
20 | type FRes (a -> f') a' = a -> FRes f' a'
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
- , . , . , (, FunDeps ) :
type family FRes f a where
FRes (Kwarg name t -> b) (Kwarg name t) = b
FRes (a -> f') a' = a -> FRes f' a'
runFun, - , GHC:
class Fun f a where
runFun :: f -> a -> FRes f a
instance {-
=> Fun (a -> f') a' where
runFun f a' = \a -> runFun (f a) a'
instance {-
runFun = id
, .
, , : .
main = putStrLn $ show
( runFun test (Value 5 :: Kwarg "some" Int) (Value 6 :: Kwarg "test" Int)
, runFun test (Value 5 :: Kwarg "test" Int) (Value 6 :: Kwarg "some" Int) )
/tmp/wtmpf-file10498.hs:34:5: error:
• Couldn't match expected type ‘Kwarg "some" Int -> b0’
with actual type ‘FRes
(Kwarg "test" a0 -> Kwarg "some" a0 -> a0) (Kwarg "test" Int)’
The type variables ‘a0’, ‘b0’ are ambiguous
• The function ‘runFun’ is applied to three arguments,
but its type ‘(Kwarg "test" a0 -> Kwarg "some" a0 -> a0)
-> Kwarg "test" Int
-> FRes
(Kwarg "test" a0 -> Kwarg "some" a0 -> a0) (Kwarg "test" Int)’
has only two
In the expression:
runFun
test (Value 5 :: Kwarg "test" Int) (Value 6 :: Kwarg "some" Int)
In the first argument of ‘show’, namely
‘(runFun
test (Value 5 :: Kwarg "some" Int) (Value 6 :: Kwarg "test" Int),
runFun
test (Value 5 :: Kwarg "test" Int) (Value 6 :: Kwarg "some" Int))’
|
34 | , runFun test (Value 5 :: Kwarg "test" Int) (Value 6 :: Kwarg "some" Int) )
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
, : . , Haskell , . , -
type family FFun a b where
. , . , , , , ; , - , , (, , ).