I have the following elm code:
import Json.Decode as Json exposing(..)
import Result
type Players = Players (List Players)
type alias Player = {
name: String
, team: Maybe Team
}
type alias Team = {
name: String
, players: Maybe Players
}
teamDecoder: Json.Decoder Team
teamDecoder =
Json.object2 Team ("name" := Json.string) (Json.maybe ("players" :=
playersDecoder))
playersDecoder: Json.Decoder Players
playersDecoder =
Json.customDecoder (Json.list playerDecoder) (\pl ->
Result.Ok (Players pl)
)
playerDecoder: Json.Decoder Player
playerDecoder =
Json.object2 Player ("name" := Json.string) (Json.maybe ("team" :=
teamDecoder))
Compiling give me the following error
-- TYPE MISMATCH
--------------------------------------------------------------- The 2nd
argument to function `customDecoder` is causing a mismatch. 26|>
Json.customDecoder (Json.list playerDecoder) (\pl ->
27|> Result.Ok (Players pl) Function `customDecoder` is expecting the 2nd
argument to be: List { name : String, team : Maybe Team } -> Result String a
But
it is: List Players -> Result a Players Hint: I always figure out the type
of arguments from left to right. If an
argument is acceptable when I check it, I assume it is "correct" in
subsequent
checks. So the problem may actually be in how previous arguments interact
with
the 2nd.
I'm wondering why this is the case? Shouldn't the pl variable inside of the
anon func be a List Players based on the type signature of
Json.customDecoder? How can I decode into the Team type alias?
Thanks!
--
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.