Recursive types
- Dominant language
- Elm
- Stars
- 107
- Forks
- 28
- PR merge metrics
- No merged PRs in 30d
Description
Hi there - there's an issue creating Elm decoders for recursive types, apparently Elm cannot handle recursive values due to it's strictness.
`jsonDecEdit` is defined directly in terms of itself, causing an infinite loop.
Maybe the solution is to give it a dummy argument to a helper function? e.g.
```
jsonDecEdit_ : () -> Json.Decode.Decoder Edit
jsonDecEdit _ = -- real decoder goes here
jsonDecEdit : Json.Decode.Decoder Edit
jsonDecEdit = jsonDecEdit_ ()
```
```
type Edit =
Add Int Object
| Delete Int
| Move (List Int) Vec2
| Multi (List Edit)
jsonDecEdit : Json.Decode.Decoder ( Edit )
jsonDecEdit =
let jsonDecDictEdit = Dict.fromList
[ ("Add", Json.Decode.map2 Add (Json.Decode.index 0 (Json.Decode.int)) (Json.Decode.index 1 (jsonDecObject)))
, ("Delete", Json.Decode.map Delete (Json.Decode.int))
, ("Move", Json.Decode.map2 Move (Json.Decode.index 0 (Json.Decode.list (Json.Decode.int))) (Json.Decode.index 1 (jsonDecVec2)))
, ("Multi", Json.Decode.map Multi (Json.Decode.list (jsonDecEdit)))
]
in decodeSumObjectWithSingleField "Edit" jsonDecDictEdit
```
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.