"Unknown data constructor CodePoint" (missing "codePointToInt"?)
kohanyirobert opened this issue · 2 comments
Using version 4.0.1 this fails
import Data.String
instance myCodePointShow :: Show CodePoint where
show (CodePoint i) = "CodePoint: " <> show i
with "Unknown data constructor CodePoint".
I got the impression that the CodePoint type constructor is not exported, so I tried using codePointToInt but there's no such function anywhere in the module. I've seen there was such a function in 3.5.0.
How to proceed? What am I missing?
Yes, the CodePoint data constructor is not exported; this is deliberate so that you can't end up with an invalid code point value (i.e. one outside of the range 0x0 - 0x10ffff or whatever it is). You can use the toEnum or fromEnum functions from the BoundedEnum instance to convert to/from integers.
I would be in favour of bringing codePoint{To,From}Int back though, personally. Monomorphic functions are good for type inference and for code clarity.
Ah, cool. Thanks for the clarification. I agree that codePoint{To,From}Int would be nice.
Just for reference:
> import Data.String
> import Data.Enum
> import Partial.Unsafe
> fromEnum (codePointFromChar 'a')
97
> toEnum 97 :: Maybe CodePoint
(Just (CodePoint 0x61)
> toEnum 9999999 :: Maybe CodePoint
Nothing