Json.decode is not lazy

65 views
Skip to first unread message

Simon

unread,
Sep 25, 2015, 2:34:51 PM9/25/15
to Elm Discuss
Been experimenting with the Json library.
I expected this to yield `[9, 9]` but instead it gave me an 'unexpected x found`. That's very surprising with the uncommented code as I use `succeed`. Likewise the `oneOf` line also gave that error. This wasn't what I expected, but perhaps I should have.  (Note that succeed was used when I decoded the commented json string with the `\"\"`.

microJson : String
microJson
= "[{\"tag\": 123}, {\"tag\": 23x4}]"
-- microJson = "[{\"tag\": 123}, {\"tag\": \"\"}]"

dec1
: Decoder (List Int)
dec1
= list (succeed 9)
-- dec1 = list <| ("tag" := int)
-- dec1 = list (oneOf [ ("tag" := int), succeed 9 ])

Janis Voigtländer

unread,
Sep 25, 2015, 3:51:13 PM9/25/15
to elm-d...@googlegroups.com
Wouldn't a more appropriate description be the following?

"Json.decode only accepts input that is at least valid JSon."
--
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 elm-discuss...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Janis Voigtländer

unread,
Sep 25, 2015, 3:55:33 PM9/25/15
to elm-d...@googlegroups.com
Maybe think about it this way: If you expected your example to work with 23x4, would you also expect it to work (by virtue of "laziness") with 23}4 or something similarly weird in that place?

Simon

unread,
Sep 25, 2015, 3:58:57 PM9/25/15
to Elm Discuss
Yes, apologies.
To unsubscribe from this group and stop receiving emails from it, send an email to elm-discuss+unsubscribe@googlegroups.com.

Joey Eremondi

unread,
Sep 25, 2015, 6:27:28 PM9/25/15
to elm-d...@googlegroups.com
It's important to remember that Elm, unlike Haskell, is NOT a lazy language. If you want lazy behavior, you need to manually wrap things in functions (i.e. () -> a ), and call those functions when you want things to be evaluated.

Yes, apologies.
To unsubscribe from this group and stop receiving emails from it, send an email to elm-discuss...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

--
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 elm-discuss...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages