-
Notifications
You must be signed in to change notification settings - Fork 0
/
Main.purs
80 lines (70 loc) · 2.12 KB
/
Main.purs
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
74
75
76
77
78
79
80
module Main where
import Prelude
import Control.Monad.Eff (Eff)
import Control.Monad.Eff.Console (CONSOLE, log, logShow)
import Data.Array as Array
import Data.List (List, (:))
import Data.Monoid (mempty)
import Type.Data.Boolean (class If, class Or)
import Type.Data.Ordering (class Equals)
import Type.Prelude (class CompareSymbol, class IsSymbol, class RowToList, EQ, LT, RLProxy(..), SProxy(..), reflectSymbol)
import Type.Row (Cons, Nil, kind RowList)
class Keys (xs :: RowList) where
keysImpl :: RLProxy xs -> List String
instance nilKeys :: Keys Nil where
keysImpl _ = mempty
instance consKeys ::
( IsSymbol name
, Keys tail
) => Keys (Cons name ty tail) where
keysImpl _ = first : rest
where
first = reflectSymbol (SProxy :: SProxy name)
rest = keysImpl (RLProxy :: RLProxy tail)
class RowListIntersection
(xs :: RowList)
(ys :: RowList)
(res :: RowList)
| xs ys -> res
instance rliNilXS :: RowListIntersection Nil (Cons name ty tail) Nil
instance rliNilYS :: RowListIntersection (Cons name ty tail) Nil Nil
instance rliNilNil :: RowListIntersection Nil Nil Nil
instance rliConsCons ::
( CompareSymbol xname yname ord
, Equals ord EQ isEq
, Equals ord LT isLt
, Or isEq isLt isEqOrLt
, If isEq xty trashty yty
, If isEq xty trashty2 zty
, If isEq (SProxy xname) trashname (SProxy zname)
, If isEq
(RLProxy (Cons zname zty res'))
(RLProxy res')
(RLProxy res)
, If isEqOrLt
(RLProxy xs)
(RLProxy (Cons xname xty xs))
(RLProxy xs')
, If isLt
(RLProxy (Cons xname yty ys))
(RLProxy ys)
(RLProxy ys')
, RowListIntersection xs' ys' res'
) => RowListIntersection (Cons xname xty xs) (Cons yname yty ys) res
getSharedLabels
:: forall r1 rl1 r2 rl2 rl
. RowToList r1 rl1
=> RowToList r2 rl2
=> RowListIntersection rl1 rl2 rl
=> Keys rl
=> Record r1
-> Record r2
-> List String
getSharedLabels _ _ = keysImpl (RLProxy :: RLProxy rl)
main :: forall e. Eff (console :: CONSOLE | e) Unit
main = do
logShow <<< Array.fromFoldable $
getSharedLabels
{ a: 123, b: "abc" }
{ a: 123, b: "abc", c: true }
log "Hello sailor!"