GenEq.dcl 942 Bytes
Newer Older
Camil Staps's avatar
Camil Staps committed
1
definition module Data.GenEq
2 3

import StdGeneric
Steffen Michels's avatar
Steffen Michels committed
4
from StdBool import qualified &&, not
5

Steffen Michels's avatar
Steffen Michels committed
6
generic gEq a  :: !a !a -> Bool
7 8

// base cases
Steffen Michels's avatar
Steffen Michels committed
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
gEq{|OBJECT|} f (OBJECT x) (OBJECT y) 		= f x y
gEq{|CONS|} f (CONS x) (CONS y) 			= f x y
gEq{|RECORD|} f (RECORD x) (RECORD y) 		= f x y
gEq{|FIELD|} f (FIELD x) (FIELD y) 			= f x y

gEq{|EITHER|} fl fr (LEFT x) (LEFT y) 		= fl x y
gEq{|EITHER|} fl fr (LEFT _) (RIGHT _) 		= False
gEq{|EITHER|} fl fr (RIGHT x) (RIGHT y) 	= fr x y
gEq{|EITHER|} fl fr (RIGHT _) (LEFT _)		= False

gEq{|UNIT|} UNIT UNIT 						= True

gEq{|PAIR|} fx fy (PAIR x1 y1) (PAIR x2 y2) = fx x1 x2 'StdBool'. && fy y1 y2

derive gEq Int, Char, Bool, Real, String, {}, {!} 
24 25

// standard types
26
derive gEq [], (), (,), (,,), (,,,), (,,,,), (,,,,,), (,,,,,,), (,,,,,,,)
27

Steffen Michels's avatar
Steffen Michels committed
28

29
//* @type a a -> Bool | gEq{|*|} a
Steffen Michels's avatar
Steffen Michels committed
30 31 32
(===) infix 4
(===) x y :== gEq{|*|} x y

33
//* @type a a -> Bool | gEq{|*|} a
Steffen Michels's avatar
Steffen Michels committed
34 35
(=!=) infix 4
(=!=) x y :== 'StdBool'.not (x === y)