I have a data family indexed by type-level list, where types in a list correspond to parameters of a data instance. I want to write function that will have different arity and parameters depending on a data instance, so I could use it like synonym for every data instance in the family.
{-# LANGUAGE KindSignatures, DataKinds, TypeOperators,
TypeFamilies, FlexibleInstances, PolyKinds #-}
module Issue where
type family (->>) (l :: [*]) (y :: *) :: * where
'[] ->> y = y
(x ': xs) ->> y = x -> (xs ->> y)
class CVal (f :: [*]) where
data Val f :: *
construct :: f ->> Val f
instance CVal '[Int, Float, Bool] where
data Val '[Int, Float, Bool] = Val2 Int Float Bool
construct = Val2
This compiles fine. But when I try to apply construct function:
v :: Val '[Int, Float, Bool]
v = construct 0 0 True
it produces error:
Couldn't match expected type `a0
-> a1 -> Bool -> Val '[Int, Float, Bool]'
with actual type `f0 ->> Val f0'
The type variables `f0', `a0', `a1' are ambiguous
The function `construct' is applied to three arguments,
but its type `f0 ->> Val f0' has none
In the expression: construct 0 0 True
In an equation for `v': v = construct 0 0 True