As it stands, you are defining two things called "Either": one is a type,
the other is a type constructor for Node.

You need to change

type Node = Either Group Datase

to

type alias Node = Either Group Dataset






On Fri, Aug 19, 2016 at 6:55 PM, Dimitri Tcaciuc <[email protected]> wrote:

> Hello,
>
> I'm trying to decode a tree structure where each node can either have
> children nodes or be a leaf and have data attached to it. Here are the
> types and a decoder I've come up with so far:
>
> type Either a b = Left a | Right b
>
> type Node = Either Group Dataset
>
> type alias Group = {
>   nodes: List Node
> }
>
> type alias Dataset = {
>   data: List Int
> }
>
>
> decodeNode =
>   ("type" := string) `andThen` (\t ->
>     case t of
>       "group" ->
>         customDecoder ("nodes" := list decodeNode) (\nodes ->
>           Left (Group nodes) |> Result.Ok
>         )
>       "dataset" ->
>         customDecoder ("data" := list int) (\values ->
>           Right (Dataset values) |> Result.Ok
>         )
>   )
>
>
>
> The full gist test data is at https://gist.github.com/dtcaciuc/
> d11b2737fa5d719faf0e5770f6f93e2e. The problem is the compiler doesn't
> seem to recognize that `Either Group Dataset` which `decodeNode` returns is
> equivalent to Node.
>
> Any ideas how to make this work?
>
> Thank you,
>
> --
> 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.
>

-- 
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.

Reply via email to