I am Haskell and Stackoverflow noob, and here is my first and probably pretty simple Haskell question.
module M where import Data.HList data R ra r1 = undefined :: R a Int r2 = undefined :: R a Double rPair :: R ra -> R rb -> (R ra, R rb) rPair = (,) rp = rPair r1 r2
This makes sense, even if r1 and r2 are polymorphic in r. RPair aligns its type r with the signature type. Is there a technical term for this "alignment"?
class HList l => RList rl instance RList r HNil instance RList rl => RList r (HCons (R ra) l) rCons :: RList rl => R ra -> l -> (HCons (R ra) l) rCons = hCons rc = rCons r1 (rCons r2 hNil)
rCons works fine if traversed R is monomorphic in r, holding back the list type r as desired. but if they are polymorphic in r, it does not align them like rPair and gives an error (rc definition above).
No instance for (RList r (HCons (R r1 Double) HNil))
I have a vague intuition as to why this is so, but my question has two parts. Can someone clearly explain the phenomenon? How would I write rCons so that the following would be?
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
source share