[elm-discuss] Re: Is there a way to get a compile-time error when a field is added to a record type but its corresponding JSON encoder is not?

2017-04-08 Thread Andres Riofrio
Wow, awesome suggestions guys. I especially like Ian's fuzzing solution. Once I'm past the prototyping phase in my project, I'll add such a fuzzer to my test suite. On Friday, April 7, 2017 at 5:48:25 AM UTC-7, Andres Riofrio wrote: > > For example, I have the following code: > > type alias Acco

[elm-discuss] Re: Is there a way to get a compile-time error when a field is added to a record type but its corresponding JSON encoder is not?

2017-04-08 Thread art yerkes
I wrote this recently: http://package.elm-lang.org/packages/prozacchiwawa/elm-json-codec/1.0.0/JsonCodec which at least for normally sized objects will fail to compile if you're missing a field in an object. It isn't perfect but one advantage is that you build encoder and decoder pairs togethe

[elm-discuss] Re: Is there a way to get a compile-time error when a field is added to a record type but its corresponding JSON encoder is not?

2017-04-07 Thread Daniel Bachler
Ian's solution is quite nice. Another way to go is that if you also have a json decoder to have an elm-test case that ensures that accountToJson >> jsonToAccount is an identity operation. For the decoder you would already get a type error and probably remember to add the new field in the encoder

[elm-discuss] Re: Is there a way to get a compile-time error when a field is added to a record type but its corresponding JSON encoder is not?

2017-04-07 Thread Ian Mackenzie
Also, not a compile-time check, but one other thing I like to do is add fuzz tests that verify that my encoders and decoders are actually inverses of each other. I create fuzzers for all of my types, and have a gener

[elm-discuss] Re: Is there a way to get a compile-time error when a field is added to a record type but its corresponding JSON encoder is not?

2017-04-07 Thread Ian Mackenzie
You could change the signature instead of the definition: accountToJson : { id : Int, name : String } -> Json.Encode.Value accountToJson act = Json.Encode.object [ ("id", Json.Encode.int act.id) , ("name", Json.Encode.string act.name) ] For example, https://ellie-app.com/RcvWmTyWFga1/0 trig