f-o-a-m / kepler

A Haskell framework that facilitates writing ABCI applications
https://kepler.dev
Apache License 2.0
34 stars 9 forks source link

implement default HasCodec instance for proto3-suite messages #134

Closed IvantheTricourne closed 4 years ago

IvantheTricourne commented 4 years ago

Any type that has a Proto3.Suite.Message instance should have a default HasCodec instance (i.e., using the codecs from Proto3.Suite).

This alleviates the need to repeatedly do this

martyall commented 4 years ago

I've already tried to do this once. You're going to run into a problem because the library is trying to support messages coming from protolens as well.

when you write instances of the form Foo a => Bar a, you will run into overlapping and undecidable instances.

IvantheTricourne commented 4 years ago

@blinky3713 I got around undecidable instances by directly implementing defaults in the HasCodec class.

default encode :: Message a => a -> BS.ByteString default decode :: Message a => BS.ByteString -> Either Text a

I did this over trying to write an instance for Message a => HasCodec a, which is an undecidable instance.

It's a bit weird (i.e., because not all instances of HasCodec necessarily refer to a proto3-suite message), but I feel like proto3-suite messages are good to default on since these already have their own codecs.