[Haskell-cafe] DataKinds and Data.Char
Oleg Grenrus
oleg.grenrus at iki.fi
Mon Dec 13 13:21:11 UTC 2021
Yes
https://github.com/ghc-proposals/ghc-proposals/pull/387
Implemented in GHC-9.2
- Oleg
On 13.12.2021 14.49, Olaf Klinke wrote:
> 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
>
> _______________________________________________
> Haskell-Cafe mailing list
> To (un)subscribe, modify options or view archives go to:
> http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
> Only members subscribed via the mailman list are allowed to post.
More information about the Haskell-Cafe
mailing list