Skip to content

Commit e07bec7

Browse files
committed
Add Mirror and Snoc type classes to Symbol
1 parent 82b343f commit e07bec7

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

src/Type/Data/Symbol.purs

Lines changed: 37 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

@@ -36,3 +41,35 @@ instance equalsSymbol
3641
equals :: forall l r o. Equals l r o => SProxy l -> SProxy r -> BProxy o
3742
equals _ _ = BProxy
3843

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

0 commit comments

Comments
 (0)