forked from augustss/MicroHs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathClass.hs
45 lines (34 loc) · 965 Bytes
/
Class.hs
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
module Class(main) where
import Primitives
import Prelude
class Eqq a where
(===) :: a -> a -> Bool
(/==) :: a -> a -> Bool
x /== y = not (x === y)
instance Eqq Int where
(===) = primIntEQ
instance Eqq Char where
(===) = primCharEQ
instance forall a . Eqq a => Eqq [a] where
[] === [] = True
(x:xs) === (y:ys) = x === y && xs === ys
_ === _ = False
class (Eqq a) => Ordd a where
(<==) :: a -> a -> Bool
instance Ordd Int where
(<==) = (<=)
instance forall a b . (Eqq a, Eqq b) => Eqq (a, b) where
(a, b) === (a', b') = a === a' && b === b'
f :: forall a . Eqq a => a -> Bool
f x = x === x
g :: forall a . Ordd a => a -> Bool
g x = x /== x
h :: forall a b . (Eqq a, Eqq b) => a -> b -> Bool
h a b = a === a && b === b
main :: IO ()
main = do
putStrLn $ show $ f (5::Int)
putStrLn $ show $ g (5::Int)
putStrLn $ show $ h (5::Int) 'a'
putStrLn $ show $ f [88::Int]
putStrLn $ show $ f (1::Int, 'a')