You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
λ> let x = FooOne "Hello"
λ> encode x
"{\"tag\":\"FooOne\",\"contents\":\"Hello\"}"
λ> let y = FooTwo $ Bar 1 True
λ> encode y
"{\"tag\":\"FooTwo\",\"contents\":{\"two\":true,\"one\":1}}"
The generated elm code for Foo and Bar have the following decoder:
decodeFoo:DecoderFoodecodeFoo =let decide :String->DecoderFoo
decide x =case x of"FooOne"->D.field "contents"<|D.map FooOne(D.index 0D.string)"FooTwo"->D.field "contents"<|D.map FooTwo(D.index 0 decodeBar)
c ->D.fail <|"Foo doesn't have such constructor: "++ c
in D.andThen decide (D.field "tag"D.string)decodeBar:DecoderBardecodeBar =D.succeed Bar|> required "one"D.int
|> required "two"D.bool
The problem is in decide function where it assumes that the values of the contents field will be an array. The generated decoders fail as can be seen here:
> D.decodeString ED.decodeFoo "{\"tag\":\"FooOne\",\"contents\":\"Hello\"}"
Err (Field "contents" (Failure ("Expecting an ARRAY") <internals>))
: Result D.Error ElmStreet.Types.Foo
> D.decodeString ED.decodeFoo "{\"tag\":\"FooTwo\",\"contents\":{\"two\":true,\"one\":1}}"
Err (Field "contents" (Failure ("Expecting an ARRAY") <internals>))
: Result D.Error ElmStreet.Types.Foo
The text was updated successfully, but these errors were encountered:
given the following Haskell types
it encodes and decodes like so:
The generated elm code for
Foo
andBar
have the following decoder:The problem is in
decide
function where it assumes that the values of thecontents
field will be an array. The generated decoders fail as can be seen here:The text was updated successfully, but these errors were encountered: