Skip to content

Commit 9d8a554

Browse files
committed
Use Int for char codes
1 parent 9905107 commit 9d8a554

File tree

3 files changed

+10
-8
lines changed

3 files changed

+10
-8
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,15 @@ Returns the string of length `1` containing only the given character.
2424
#### `toCharCode`
2525

2626
``` purescript
27-
toCharCode :: Char -> Number
27+
toCharCode :: Char -> Int
2828
```
2929

3030
Returns the numeric Unicode value of the character.
3131

3232
#### `fromCharCode`
3333

3434
``` purescript
35-
fromCharCode :: Number -> Char
35+
fromCharCode :: Int -> Char
3636
```
3737

3838
Constructs a character from the given Unicode numeric value.

bower.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
"package.json"
1919
],
2020
"dependencies": {
21-
"purescript-maybe": "~0.2.1"
21+
"purescript-maybe": "~0.2.1",
22+
"purescript-integers": "~0.1.0"
2223
}
2324
}

src/Data/Char/Char.purs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ module Data.Char
66
, toCharCode
77
) where
88

9+
import Data.Int (Int(), fromNumber)
10+
911
--| A unicode character.
1012
newtype Char = Char String
1113

@@ -19,29 +21,28 @@ foreign import toCharCode
1921
function toCharCode(c) {
2022
return c.charCodeAt(0);
2123
}
22-
""" :: Char -> Number
24+
""" :: Char -> Int
2325

2426
-- | Constructs a character from the given Unicode numeric value.
2527
foreign import fromCharCode
2628
"""
2729
function fromCharCode(c) {
2830
return String.fromCharCode(c);
2931
}
30-
""" :: Number -> Char
32+
""" :: Int -> Char
3133

3234
-- | Characters can be compared for equality with `==` and `/=`.
3335
instance eqChar :: Eq Char where
3436
(==) (Char a) (Char b) = a == b
35-
3637
(/=) a b = not (a == b)
3738

3839
-- | Characters can be compared with `compare`, `>`, `>=`, `<` and `<=`.
3940
instance ordChar :: Ord Char where
4041
compare (Char a) (Char b) = a `compare` b
4142

4243
instance boundedChar :: Bounded Char where
43-
top = fromCharCode 0
44-
bottom = fromCharCode 65535
44+
top = fromCharCode zero
45+
bottom = fromCharCode (fromNumber 65535)
4546

4647
-- | Characters can be rendered as a string with `show`.
4748
instance showChar :: Show Char where

0 commit comments

Comments
 (0)