It is basically a side effect of
https://github.com/elm-lang/elm-compiler/issues/873 (in an incarnation like
https://github.com/elm-lang/elm-compiler/issues/1341) that your Attempt 1
does not work while Attempt 2 does.
​

2016-05-05 9:19 GMT+02:00 Daniel Kinney <[email protected]>:

> I have a simple recursive data type.
>
> type  Tree = Tree TreeRecord
> type alias TreeRecord =
>   { children : List Tree }
>
> I attempted to decode it using the following, and ended up scratching my
> head for a long time trying to figure out what was wrong. (I get a cryptic 
> 'Err
> ("d1 is not a function")'. A tried sleuthing through the JS without much
> luck.)
>
> (Attempt 1)
>
> decoderWithWrap =
>   map Tree <| decoderPartial
>
> decoderPartial =
>   object1
>     TreeRecord
>     ("children" := list (lazy (\_ -> decoderWithWrap)))
>
> So I got help from the thread JSON Decoder for recursive structure
> <https://groups.google.com/forum/#!searchin/elm-discuss/recursive$20json/elm-discuss/6IiESi_sOUE/s_yyebsFy_gJ>,
> which led me to rewrite my code:
>
> (Attempt 2)
>
> decoder =
>   map Tree <|
>     object1
>       TreeRecord
>       ("children" := list (lazy (\_ -> decoder)))
>
> This works brilliantly, but I am still left scratching my head because to
> my eyes, these look like they should be equivalent. Is there any particular
> reason why attempt #1 fails, but attempt #2 works?
>
> --
> 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