[Haskell-cafe] DataKinds and Data.Char

Olaf Klinke olf at aatal-apotheke.de
Mon Dec 13 12:49:19 UTC 2021


Dear Café,

Question: Is DataKinds promotion of Char values possible, and if yes,
how? 

I want to define a data type of text where a certain character has
special meaning. I could say:
    data SpecialText = SpecialText Char Text
but it would be favourable if the type system forbids combining texts
with distinct special characters. 
    data SpecialText char = SpecialText Text
Ideally, we could use DataKinds to specialize the char phantom type
parameter to a promoted Char value, but neither 'x' nor ''x' is
accepted by GHC, presumably for good reasons. After all, 'x' is
syntactic sugar for the real constructor of a Char value (which is
what? Data.Data.toConstr 'x' yields 'x'.)

One certainly can define data types symbolizing selected single Char
values to use as the phantom type, but that means the library author
decides which Chars the user can declare as special. 

Thanks
Olaf



More information about the Haskell-Cafe mailing list