[Haskell-cafe] type level strings?

Evan Laforge qdunkan at gmail.com
Thu Nov 24 01:06:48 CET 2011


On Wed, Nov 23, 2011 at 4:03 PM, Holger Reinhardt <hreinhardt at gmail.com> wrote:
> 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...



More information about the Haskell-Cafe mailing list