Expand description
Writing a universe out as Haskell.
Structs become records and enums become sums, each with a ToJson and a
FromJson instance that read and write exactly the wire form, so a value
built from the generated types is the value unitype says it is.
§No JSON library
GHC ships none, and the usual one is a build of its own dependency tree. So
the instances are written against a small module generated beside the
universes, UnitypeSupport, the way Rust’s shared Bytes is: it reads and
writes JSON and base64 using only what comes with GHC — base,
bytestring, containers, text. A generated universe compiles with a
bare ghc, with no package database and no network.
§Names
Haskell puts every field, constructor and function in a module into one
space, where the other targets give each struct its own. Two structs that
both have an id cannot both have a field called id, and an inherited
one is carried by the child too. So a field is named after the type that
holds it — circleId, circleRadius — which is also what a reserved word
cannot be, and a variant after its enum — SizeLarge. The wire keeps its
own names, written into the instances. If two declarations would still come
out as one name, generation says so rather than choosing.
§Inheritance
Haskell has none, so a child carries every field it has, inherited or not, as Rust does. An interface becomes a class of accessors, and a struct that claims one gets an instance, so a bound on a generic parameter is a class constraint.
§Bodies
A body is written with the Prelude qualified, so a parameter called length
or map cannot capture what the body means by them; nothing from the
Prelude is imported by name but the types and the operators. The checker
takes a T wherever a T? is wanted and Haskell does not, so a body is
written knowing what each part produces and what the place it stands in
wants, which is Just where a value that is there goes into one that may
not be.
Structs§
- Haskell
- The Haskell backend.
Functions§
- literal
- Writes a value as a Haskell literal, with no type to guide it.
- record
- Builds a named struct from its
field = valueparts. - string_
literal - Writes a Haskell string literal.
- typed_
literal - Writes a value as a Haskell literal of
ty. - variant
- Builds one alternative of a named enum.