react-fontawesome
react-fontawesome copied to clipboard
Haskell: Use typeclasses for types that can be encoded and decoded by typedefs.
Right now, the Haskell backend relies on explicitly calling serialisation function for types that depend on other types. For example:
(name List (mu (Nil 1) (Cons (* (var 1) (var 0)))))
generates
encodeList :: Serialiser x0 -> Serialiser (List x0)
decodeList :: Deserialiser x0 -> Deserialiser (List x0)
which makes it very difficult to use from the haskell side since every call has to pass the x0
's serialiser explicitly.
Using a typeclass we could generate the following code instead.
class TypedefCodec t where
encode :: Serialiser t
decode :: Deserialiser t
instance (TypedefCodec x) => TypdefCodec (List x) where
encode = …
decode = …
which allows to use encode
and decode
on List a
without having to pass the serialiser for a
explicitly as long as there is an instance for a
.