-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCh7.hs
More file actions
38 lines (28 loc) · 872 Bytes
/
Ch7.hs
File metadata and controls
38 lines (28 loc) · 872 Bytes
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
module Ch7 where
tensDigit :: Integral a => a -> a
tensDigit x = d
where xLast = x `div` 10
d = xLast `mod` 10
tensDigit' :: Integral a => a -> a
tensDigit' x = snd $ divMod (fst (divMod x 10)) 10
hunsDigit' :: Integral a => a -> a
hunsDigit' x = snd $ divMod (fst (divMod x 100)) 100
foldBool :: a -> a -> Bool -> a
foldBool x y b
| b==False = x
| b==True = y
foldBool' :: a -> a -> Bool -> a
foldBool' x y b = case b of
False -> x
True -> y
g :: (a -> b) -> (a,c) -> (b,c)
g f (a,c) = (f a, c)
roundTrip :: (Show a, Read a) => a -> a
roundTrip a = read (show a)
roundTrip' :: (Show a, Read a) => a -> a
roundTrip' = read . show
roundTrip'' :: (Show a, Read b) => a -> b
roundTrip'' x = (read ((show x) :: String))
-- here's how you call it:
-- (roundTrip'' 435) :: Int
-- roundTrip'' "lsdkf" :: String