Bijection between Char and Fin Char.numCodePoints #
In this file, we construct a bijection between Char and Fin Char.numCodePoints and show that
it is compatible with various operations. Since Fin is simpler than Char due to being based
on natural numbers instead of UInt32 and not having a hole in the middle (surrogate code points),
this is sometimes useful to simplify reasoning about Char.
We use these declarations in the construction of Char ranges, see the module
Init.Data.Range.Polymorphic.Char.
The number of surrogate code points.
Equations
- Char.numSurrogates = 2048
Instances For
Packs Char bijectively into Fin Char.numCodePoints by shifting code points which are
greater than the surrogate code points by the number of surrogate code points.
The inverse of this function is called Char.ofOrdinal.
Equations
Instances For
Unpacks Fin Char.numCodePoints bijectively to Char by shifting code points which are
greater than the surrogate code points by the number of surrogate code points.
The inverse of this function is called Char.ordinal.
Equations
- Char.ofOrdinal f = if h : ↑f < 55296 then { val := UInt32.ofNatLT ↑f ⋯, valid := ⋯ } else { val := UInt32.ofNatLT (↑f + Char.numSurrogates) ⋯, valid := ⋯ }
Instances For
Computes the next Char, skipping over surrogate code points (which are not valid
Chars) as necessary.
This function is specified by its interaction with Char.ordinal, see
Char.succ?_eq.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Computes the m-th next Char, skipping over surrogate code points (which are not
valid Chars) as necessary.
This function is specified by its interaction with Char.ordinal, see
Char.succMany?_eq.
Equations
- Char.succMany? m c = Option.map Char.ofOrdinal (c.ordinal.addNat? m)