Elm Exactly
Results / elm-bytes /

BytesDecoderSelfRecursiveMinimalTest

elm-0.19.1 passelm-0.19.2 passelm-0.19.3 passlamdera-1.5.0 pass
A top-level decoder value that refers to itself inside `Bytes.Decode.andThen` decodes a small tree correctly.

`tDecoder` takes no arguments; it reads a tag byte and, for tag `1`, uses
itself twice to read the two subtrees of a `TPair`. Tag `0` is `TLeaf`.

The input `1 0 0` decodes to `Just (TPair TLeaf TLeaf)`.

Results

elm-0.19.1

passran in 65 ms
Output
Compiled in DEV mode. Follow the advice at https://elm-lang.org/0.19.1/optimize for better performance and smaller assets.
decoded: Just (TPair TLeaf TLeaf)

elm-0.19.2

passran in 68 ms
Output
Compiled in DEV mode. Follow the advice at https://elm-lang.org/0.19.2/optimize for better performance and smaller assets.
decoded: Just (TPair TLeaf TLeaf)

elm-0.19.3

passran in 58 ms
Output
Compiled in DEV mode. Follow the advice at https://elm-lang.org/0.19.3/optimize for better performance and smaller assets.
decoded: Just (TPair TLeaf TLeaf)

lamdera-1.5.0

passran in 60 ms
Output
decoded: Just (TPair TLeaf TLeaf)

Discussions

Discuss this test·Search the discussions on GitHub

Discussions are on GitHub; one about this test has [t:elm-bytes/BytesDecoderSelfRecursiveMinimalTest] in its title.

Source

The -- CHECK: lines give the expected output.

module BytesDecoderSelfRecursiveMinimalTest exposing (main)
{-| A top-level decoder value that refers to itself inside `Bytes.Decode.andThen` decodes a small tree correctly.
`tDecoder` takes no arguments; it reads a tag byte and, for tag `1`, uses
itself twice to read the two subtrees of a `TPair`. Tag `0` is `TLeaf`.
The input `1 0 0` decodes to `Just (TPair TLeaf TLeaf)`.
-}
-- CHECK: decoded: Just (TPair TLeaf TLeaf)
import Bytes.Decode as D
import Bytes.Encode as E
import Html exposing (text)
type T
= TLeaf
| TPair T T
tDecoder : D.Decoder T
tDecoder =
D.unsignedInt8
|> D.andThen
(\b ->
case b of
0 ->
D.succeed TLeaf
1 ->
D.map2 TPair tDecoder tDecoder
_ ->
D.fail
)
main =
let
bytes =
E.encode
(E.sequence
[ E.unsignedInt8 1
, E.unsignedInt8 0
, E.unsignedInt8 0
]
)
result =
D.decode tDecoder bytes
_ =
Debug.log "decoded" result
in
text "done"