haskell - Defined a type family (++); any way to prove that (vs ++ us) ~ '[] implies (vs ~ '[]) and (us ~ '[])? -


defined:

type family (xs :: [*]) ++ (ys :: [*])   '[] ++ ys = ys   (x ': xs) ++ ys = x ': (xs ++ ys) 

i have gadt that's kinda like

data foo :: [*] -> * -> *   foo0 :: -> foo '[]   foo1 :: foo '[a]   foo2 :: foo vs -> foo -> foo (vs ++ us) 

and want like

test :: foo '[] int -> int test (foo0 x) = x test (foo2 x y) = test x + test y 

but can't use test on x or y because x ~ foo '[] int , y ~ foo '[] int have proven. want proven fact vs ++ ~ '[] means individual vs , us of x , y '[].

is there way type families, or maybe switching on multi param typeclass approach fundeps?

thanks!

don't touch green smile!

the presence of ‘green slime’ — defined functions in return types of constructors — danger sign.

the simplest workaround generalize test , instantiate:

gtest :: foo xs int -> int gtest (foo0 x) = x gtest (foo2 x y) = gtest x + gtest y  test :: foo '[] int -> int test = gtest 

Comments