agrafix / agrafix/elm-bridge

Recursive types

未關閉
#22 6 則留言 1 個 reaction 已指派 0 人 在 GitHub 檢視
主要語言
Elm
星號
107
分支
28
PR 合併指標
30 天內沒有已合併 PR

描述

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

貢獻指南

這個儲存庫沒有索引到貢獻指南

評估

這個 Issue 還沒有評估資料。

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。