
8 Oct
2014
8 Oct
'14
8:28 a.m.
Is there an analog or variant of type families that is indexed by values rather than by types? An example of such a family is integers mod p. One wants to define the operations once for all p, so that a type for any particular p can be introduced by a one-line declaration. Of course this can be done with p being a run-time parameter: data Modp = Modp Integer Int instance Num (Modp) where (Modp x p) + (Modp y q) = if p==q then Modp ((x+y) 'mod' p) p else error "unequal moduli in Modp operation" But it would be better to catch the error at compile time and not have to check at every operation. Doug