I'm a Haskell and a Stackoverflow noob, and here's my first & probably quite basic Haskell question.
module M where
import Data.HList
data R r a
r1 = undefined :: R a Int
r2 = undefined :: R a Double
rPair :: R r a -> R r b -> (R r a, R r b)
rPair = (,)
rp = rPair r1 r2
This makes sense, even if r1 & r2 are polymorphic in r rPair aligns their r type in accordance with the type signature. Is there a technical term for this 'alignment'?
class HList l => RList r l
instance RList r HNil
instance RList r l => RList r (HCons (R r a) l)
rCons :: RList r l => R r a -> l -> (HCons (R r a) l)
rCons = hCons
rc = rCons r1 (rCons r2 hNil)
rCons works great if the R's passed are monomorphic in r, constraining the list's r type as desired. but if they are polymorphic in r it does not align them the way rPair does, and gives an error (defining rc above).
No instance for (RList r (HCons (R r1 Double) HNil))
I have a vague intuition as to why this is the case, but my question is in two parts. Could somebody clearly explain the phenomenon? How would I write an rCons such that the following would hold?
r1 = undefined :: R a Int
r2 = undefined :: R a Double
rc :: HCons (R a Int) (HCons (R a Double) HNil)
rc = rCons r1 (rCons r2 hNil)
Thanks, _c