
23 Nov
2011
23 Nov
'11
7:06 p.m.
On Wed, Nov 23, 2011 at 4:03 PM, Holger Reinhardt
You can do this with phantom types, i.e.:
data Thing a = Thing Stuff
instance Monoid (Thing a) where mappend (Thing stuff1) (Thing stuff2) = Thing (stuff1 `mappend` stuff2) mempty = Thing mempty
data ID1 data ID2
thing1 :: Thing ID1 thing1 = Thing Stuff
thing2 :: Thing ID2 thing2 = Thing Stuff
-- will not typecheck: f = thing1 `mappend` thing2
Well yes, but the key feature is that the IDs are arbitrary strings. And they're not knowable at compile time, since they are read from user input...