What we want is to have some way to describe correspondence between user data types and TOML representation. Consider this Haskell data type:
data Node = Node { root :: Bool, labels :: [Int] }
Would be great to have an ability to specify correspondence in some way like this:
nodeToml :: TomlM Node
nodeToml = do
root <- bool "root"
labels <- array @Int "labels"
pure Node{..}
And then we can have two functions:
decode :: Toml -> TomlM a -> Either DecodeError a
encode :: a -> TomlM a -> Toml
Difficult questions
- How this data type should be encoded in TOML?
Like this:
node.root = true
node.labels = [ 1, 2, 3 ]
or like this:
[node]
root = true
labels = [ 1, 2, 3 ]
I think we should give an ability to specify which way user want.
- How to encode sum types?
I propose the following strategy: if you have foo :: Either Int String then it should be either
or
If you have both keys, this should be a type error. And, again, give ability to specify foo as table. And this scheme easily can be extended if constructors have multiple fields.
- What to do with arrays of different values?
In TOML it's possible to have:
foo = [ [1, 2, 3], [true, false] ]
But Haskell doesn't really have a standard data structure for such case... So should we care about supporting this case or not?..
What we want is to have some way to describe correspondence between user data types and TOML representation. Consider this Haskell data type:
Would be great to have an ability to specify correspondence in some way like this:
And then we can have two functions:
Difficult questions
Like this:
or like this:
I think we should give an ability to specify which way user want.
I propose the following strategy: if you have
foo :: Either Int Stringthen it should be eitheror
If you have both keys, this should be a type error. And, again, give ability to specify
fooas table. And this scheme easily can be extended if constructors have multiple fields.In TOML it's possible to have:
But Haskell doesn't really have a standard data structure for such case... So should we care about supporting this case or not?..