Skip to content

Commit e69ed7a

Browse files
committed
Add Mirror and Snoc type classes to Symbol
1 parent 83ddcdb commit e69ed7a

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

src/Type/Data/Symbol.purs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@ module Type.Data.Symbol
55
, compare
66
, uncons
77
, class Equals
8+
, class Mirror
9+
, class MirrorP
10+
, mirror
11+
, class Snoc
12+
, snoc
813
, equals
914
) where
1015

@@ -33,3 +38,36 @@ instance equalsSymbol
3338

3439
equals :: forall proxy l r o. Equals l r o => proxy l -> proxy r -> Proxy o
3540
equals _ _ = Proxy
41+
42+
43+
-- Mirror
44+
45+
class MirrorP (a :: Symbol) (mirror :: Symbol) | a -> mirror, mirror -> a
46+
47+
instance mirrorEmpty :: MirrorP "" ""
48+
else
49+
instance mirrorCons :: (Cons head tail sym, MirrorP tailMirror tail, MirrorP tail tailMirror, Append tailMirror head mirror) => MirrorP sym mirror
50+
51+
class Mirror (a :: Symbol) (mirror :: Symbol) | a -> mirror, mirror -> a
52+
53+
instance mirrorMirrorP :: (MirrorP a b, MirrorP b a) => Mirror a b
54+
55+
mirror :: a b. Mirror a b => SProxy a -> SProxy b
56+
mirror _ = SProxy
57+
58+
-- Snoc
59+
60+
--| ```purescript
61+
--| Snoc "symbo" "l" ?x ~~> ?x = "symbol"
62+
--| Snoc ?a ?b "symbol" ~~> ?a = "symbo", ?b = "l"
63+
--| ```
64+
-- | `end` must be a single character
65+
class Snoc (list :: Symbol) (end :: Symbol) (symbol :: Symbol) | end list -> symbol, symbol -> end list
66+
67+
instance snocMirror :: (Mirror sym mirror, Cons end listMirror mirror, Mirror listMirror list) => Snoc list end sym
68+
69+
--| ```purescript
70+
--| snoc (SProxy :: SProxy "symbo") (SProxy :: SProxy "l") = SProxy :: SProxy "symbol"
71+
--| ```
72+
snoc :: a b c. Snoc a b c => SProxy a -> SProxy b -> SProxy c
73+
snoc _ _ = SProxy

0 commit comments

Comments
 (0)