-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtailbug.hs
73 lines (60 loc) · 1.95 KB
/
tailbug.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
{-# LANGUAGE EmptyDataDecls #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE FunctionalDependencies #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE UndecidableInstances #-}
{-# LANGUAGE OverlappingInstances #-}
main = main
data HNil = HNil
data HCons e l = HCons e l
data HEmpty = HEmpty
data HNode e t t' = HNode e t t'
type HLeaf e = HNode e HEmpty HEmpty
hLeaf e = HNode e HEmpty HEmpty
newtype SkewRecord r = SkewRecord r
emptySkewRecord :: SkewRecord HNil
emptySkewRecord = SkewRecord HNil
class HUpdate l e r r' | l e r -> r' where
hUpdate :: l -> e -> r -> r'
class HSkewUpdate l e r r' | l e r -> r' where
hSkewUpdate :: l -> e -> r -> r'
instance HSkewUpdate l e HNil HNil where
hSkewUpdate _ _ = id
instance HSkewUpdate l e HEmpty HEmpty where
hSkewUpdate _ _ = id
instance
( HSkewUpdate l e t t'
, HSkewUpdate l e ts ts') =>
HSkewUpdate l e (HCons t ts) (HCons t' ts') where
hSkewUpdate l e (HCons t ts) =
HCons
(hSkewUpdate l e t)
(hSkewUpdate l e ts)
instance
( HSkewUpdate l e e' e''
, HSkewUpdate l e tl tl'
, HSkewUpdate l e tr tr') =>
HSkewUpdate l e (HNode e' tl tr) (HNode e'' tl' tr')
where
hSkewUpdate l e (HNode e' tl tr) =
HNode
(hSkewUpdate l e e')
(hSkewUpdate l e tl)
(hSkewUpdate l e tr)
class HSkewTail ts ts' | ts -> ts' where
hSkewTail :: ts -> ts'
class HRemove l r r' | l r -> r' where
hRemove :: l -> r -> r'
instance
( HSkewUpdate l e (HCons (HNode e t t') ts) r'
, HSkewTail r' r'') =>
HRemove
l
(SkewRecord (HCons (HNode e t t') ts))
(SkewRecord r'') where
hRemove l (SkewRecord (HCons (HNode e t t') ts)) =
SkewRecord $
hSkewTail $
hSkewUpdate l e (HCons (HNode e t t') ts)