-
Notifications
You must be signed in to change notification settings - Fork 1
/
DataChar.fr
49 lines (37 loc) · 1.35 KB
/
DataChar.fr
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
module learnyou.chapter07.DataChar where
import frege.Prelude hiding ( isNumber )
import frege.data.List
import frege.data.Char
encode :: Int -> String -> String
encode shift msg =
let ords = map ord $ unpacked msg
shifted = map (+ shift) ords
in packed $ map chr shifted
decode :: Int -> String -> String
decode shift msg = encode (negate shift) msg
main _ = do
println $ all isAlphaNum "bobby283".toList
println $ all isAlphaNum "eddy the fish!".toList
println $ words "hey guys its me"
println $ filter (not . any isSpace) . groupBy ((==) `on` isSpace) $
"hey guys its me".toList
println $ generalCategory ' '
println $ generalCategory 'A'
println $ generalCategory 'a'
println $ generalCategory '.'
println $ generalCategory '9'
println $ map generalCategory " \t\nA9?|".toList
println $ map digitToInt "34538".toList
println $ map digitToInt "FF85AB".toList
println $ intToDigit 15
println $ intToDigit 5
println $ ord 'a'
println $ chr 97
println $ map ord "abcdefgh".toList
println $ encode 3 "Heeeeey"
println $ encode 4 "Heeeeey"
println $ encode 1 "abcd"
println $ encode 5 "Marry Christmas! Ho ho ho!"
println $ encode 3 "Im a little teapot"
println $ decode 3 "Lp#d#olwwoh#whdsrw"
println $ decode 5 . encode 5 $ "This is a sentence"