New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Json.Decoder for objects with more than 8 arguments #514

Closed
tiziano88 opened this Issue Mar 1, 2016 · 2 comments

Comments

Projects
None yet
2 participants
@tiziano88

tiziano88 commented Mar 1, 2016

I am working on a plugin to generate protobuf bindings for Elm (https://github.com/tiziano88/elm-protobuf); it uses the Json.Decode package to deserialize JSON into Elm objects, but it is hitting the limitations of the objectN combinators in that package; it is not unusual for protobuf objects to have dozens of fields, but the Json.Decode package only offers up to object8 as a convienence to build objects from other combinators.

I believe if Elm had a way of expressing Applicative Functors, this pattern would fall into that scope (e.g. obj <$> dec1 <*> dec2 <*> dec3 ...), and there would be no need for all the overloaded versions of this combinator, but currently, it seems inevitable.

So my question is: should I rely on some more custom way of deserializing JSON for large objects, or should we increase the number of overloaded objectN, or something else entirely?

Please let me know if you have any suggestions at all, I am happy to discuss alternatives.

See here for an example code generated by the protobuf plugin that uses object7.

@jvoigtlaender

This comment has been minimized.

Show comment
Hide comment
@jvoigtlaender

jvoigtlaender Mar 1, 2016

Contributor

You may want to use the (|:) operator: http://package.elm-lang.org/packages/circuithub/elm-json-extra/latest/Json-Decode-Extra#|:.

Generally, for such discussion, please use the mailing list. This issue tracker here serves a different purpose.

Contributor

jvoigtlaender commented Mar 1, 2016

You may want to use the (|:) operator: http://package.elm-lang.org/packages/circuithub/elm-json-extra/latest/Json-Decode-Extra#|:.

Generally, for such discussion, please use the mailing list. This issue tracker here serves a different purpose.

@tiziano88

This comment has been minimized.

Show comment
Hide comment
@tiziano88

tiziano88 Mar 1, 2016

Thanks @jvoigtlaender, that makes perfect sense, I didn't realise Json.Decode already has an andThen operator, which makes it a Monad and hence also an Applicative Functor already. I have modified my plugin already, emulating an Applicative-style syntax, although it is only bound to the Json.Decode instance (I really wish Elm had HKTs so that this pattern could be generalised).

Apologies for not posting to the appropriate medium, I shall take more care going forward.

tiziano88 commented Mar 1, 2016

Thanks @jvoigtlaender, that makes perfect sense, I didn't realise Json.Decode already has an andThen operator, which makes it a Monad and hence also an Applicative Functor already. I have modified my plugin already, emulating an Applicative-style syntax, although it is only bound to the Json.Decode instance (I really wish Elm had HKTs so that this pattern could be generalised).

Apologies for not posting to the appropriate medium, I shall take more care going forward.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment