I have created a very simple example of a problem I\'m having using GADTs and DataKinds. My real application is obviously more complicated but this captures the essence of my si
You have two options here. Either you can infer the type of the return value from the types of arguments or you can't.
In the former case, you refine the type:
data Which :: TIdx -> * where
Fst :: Which TI
Snd :: Which TD
prob :: Which i -> T1 -> T2 -> Test i
prob Fst x y = x
prob Snd x y = y
In the latter case, you have to erase the type information:
prob :: Bool -> T1 -> T2 -> Either Int Double
prob True (T1 x) y = Left x
prob False x (T2 y) = Right y
You can also erase the type information by using an existential type:
data SomeTest = forall i . SomeTest (Test i)
prob :: Bool -> T1 -> T2 -> SomeTest
prob True x y = SomeTest x
prob False x y = SomeTest y
In this case, you cannot do anything interesting with a value of SomeTest
, but you might be able in your real example.