On Thursday, September 29, 2016 at 12:34:40 AM UTC+1, Kasey Speakman wrote:
>
> In the longer term, the solution that jumps out at me is the compiler
> could generate decoders for marked type aliases automatically. (I assume
> ports work this way already.) And decoding is still there for fuzzy
> scenarios.
>
+1 to the idea.
I have already resorted to code genning data type, encoder and decoder for
REST interfaces, for which I hold a model describing the data that the
interface talks (think Swagger definition).
Some scnearios that would need to be covered:
Optional fields:
Some use Maybe, some set a default value like "". Maybe is a purer approach
but I can appreciate the sheer convenience of "" too.
Recursion:
I have data structures where a record can hold another of the same type
(think parent/child relationship in a tree), or where one record can hold
an instance of another that can hold an instance of the original giving
rise to mutual recursion. To solve that I just always use a singleton union
wrapper type:
type User =
User
{ name : String
, email : String
, birthday : Date
, id : Int
}
its a PITA, but one that using codegen for the encoder and decoder goes
some way towards making less of a hassle.
--
You received this message because you are subscribed to the Google Groups "Elm
Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.