@@ -1,14 +1,20 @@
1−module Prelude.Char
1+module Prelude.Chars
22-- Functions operating over Chars
33
44import Prelude.Bool
55import Prelude.Classes
66import Prelude.List
7+import Prelude.Cast
78import Builtins
89
910||| Return the ASCII representation of the character.
1011chr : Int -> Char
11−chr x = prim__intToChar x
12+chr x = if (x >= 0 && x < 0x11000)
13+ then assert_total (prim__intToChar x)
14+ else '\0'
15+
16+instance Cast Int Char where
17+ cast = chr
1218
1319||| Convert the number to its ASCII equivalent.
1420ord : Char -> Int
@@ -48,14 +54,14 @@ isNL x = x == '\r' || x == '\n'
4854||| Non-letters are ignored.
4955toUpper : Char -> Char
5056toUpper x = if (isLower x)
51− then (prim__intToChar (prim__charToInt x - 32))
57+ then assert_total (prim__intToChar (prim__charToInt x - 32))
5258 else x
5359
5460||| Convert a letter to the corresponding lower-case letter, if any.
5561||| Non-letters are ignored.
5662toLower : Char -> Char
5763toLower x = if (isUpper x)
58− then (prim__intToChar (prim__charToInt x + 32))
64+ then assert_total (prim__intToChar (prim__charToInt x + 32))
5965 else x
6066
6167||| Returns true if the character is a hexadecimal digit i.e. in the range [0-9][a-f][A-F]