Skip to content

Instantly share code, notes, and snippets.

@tonymorris
Last active September 24, 2016 18:44
Show Gist options
  • Save tonymorris/85fbb43d09ec75e7c34c to your computer and use it in GitHub Desktop.
Save tonymorris/85fbb43d09ec75e7c34c to your computer and use it in GitHub Desktop.
20 minutes of thinking about, "a serialisation format that sucks less than JSON, XML, YAML, BLAML, BLAH BLAH FARKINELLMATE"
  • 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.
  • Left + (7 + (() * ()))

    • Left 7 :: Either Int a
    • This 7 :: These Int a
    • Const 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 7

    • Left 7 :: Either Int a
    • This 7 :: These Int a
    • Const 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")))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment