I would like to define a data type in Haskell which is parametrized by an Int
constant along the lines:
data Q (n :: Int) = Q n (Int,Int) -- non-working code
in order to allow me to define functions of the type:
addQ :: (Q n)->(Q n)->(Q n)
addQ (Q k (i1,j1)) (Q k (i2,j2))) = Q k (i1+i2,j1+j2)
The idea is that in this way I am able to restrict addition to Q
's that have the same n
. Intuitively, it feels that this should be possible, but so far all my (admittedly newbie) attempts have stranded on the rigors of GHC.