users : Maybe (List User)
users = decode userJson

one could just make use of type inference to know what to decode into. 
Might mean another special pseudo-typeclass (like comparable, appendable) 
called decodable. Then decode (might need renaming) would have a signature 
like:

decode : Value -> Maybe decodable


I have thought about this as well, also contemplating the port option and 
also finding the amount of boilerplate you have to write to decode into 
records a little annoying. I would be tempted to also provide something like

decodeWithOptions : DecoderOptions -> Value -> decodable

where options could include a function to transform keys into record keys.


On Thursday, 29 September 2016 01:02:29 UTC+1, Duane Johnson wrote:
>
>
> On Wed, Sep 28, 2016 at 5:34 PM, Kasey Speakman <[email protected] 
> <javascript:>> 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.
>>
>
> That sounds like a neat idea. I'm trying to imagine how it would be 
> implemented. Would you pass a type in to a decode function? e.g.
>
> ``elm
> type alias User =
>     { name : String
>     , email : String
>     , birthday : Date
>     , id : Int
>     }
>
> user1Json = """[
>     {"name": "Duane", "email": "[email protected] <javascript:>", 
> "birthday": "19800101T000000Z", id: 42},
>     {"name": "Kasey Speakman", "email": "[email protected] <javascript:>", 
> "birthday": "19810202T000000Z", id: 43}
> ]"""
> ```
>
> -- the following is currently invalid Elm
> user1 = decode(List User, user1Json)
> ```
>
>
>

-- 
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.

Reply via email to