-
All things are either:
- A sum, which is a hypothetical/potential (not necessarily corresponding) constructor name, followed by
+, followed by one or more things. - A product, which is a hypothetical/potential (not necessarily corresponding) field name, followed by
*, followed by exactly one thing.
- A sum, which is a hypothetical/potential (not necessarily corresponding) constructor name, followed by
-
Left + (7 + (() * ()))Left 7 :: Either Int aThis 7 :: These Int aConst 7 :: Const Int a
-
name * (Cons + (F + (() * ())) (Cons + (r + (() * ())) (Cons * (e + (() * ())) (Cons + (d + (() * ())) Nil))))name = "Fred" :: HasName a => a (class HasName a where name :: Lens' a String)
-
, * (9 + (() * ())) (Right + (8 + (() * ()))(,) 9 (Right 8) :: (Int, Either a Int)- ... etc
Bit clumsy. Let's introduce aliases (=).
-
unit = (* () ()) -
left a = Left + ($a + :unit) -
:left 7Left 7 :: Either Int aThis 7 :: These Int aConst 7 :: Const Int a
-
cons h t = Cons + ($h + :unit) $t -
name * (:cons F (:cons r (:cons e (:cons d Nil))))name = "Fred" :: HasName a => a (class HasName a where name :: Lens' a String)
data T =
Product
| Sum
data S =
S
(Maybe String) -- name (non-empty)
T
(Either String S)
a =
S (Just "Left") Sum (Left "7")
b =
S (Just "age") Product (Right (S (Just "7") Product (Right (S (Just "name") Product (Left "Fred")))))