kowainik / tomland

🏝 Bidirectional TOML serialization
https://kowainik.github.io/posts/2019-01-14-tomland
Mozilla Public License 2.0
122 stars 39 forks source link

Simplify 'Codec' abstraction #263

Closed chshersh closed 4 years ago

chshersh commented 4 years ago

Currently, we have the following Codec abstract data type:

data Codec r w c a = Codec
    { codecRead :: r a
    , codecWrite :: c -> w a
    }

But in this library it's used only for TomlCodec:

type TomlCodec a = Codec Env St a a

It could be a good simplification to combine two and have

data Codec in out = Codec
    { codecRead :: TomlEnv out
    , codecWrite :: in -> TomlState out
    }

type TomlCodec a = Codec a a

What do you think? With this approach, we can have a single module Toml.Codec with all general functions, encoding and decoding functions instead of two modules Toml.Monad and Toml.Code