Created
December 24, 2017 08:26
-
-
Save dvberkel/497badaf71eca56ff570566a0a58d75e to your computer and use it in GitHub Desktop.
Minimal project demonstrating a problem with elm-community/parser-combinators
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module CombineProblem exposing (..) | |
import Html | |
import Combine exposing (..) | |
import Combine.Num exposing (int) | |
main = | |
parse command "[5M]" | |
|> toString | |
|> Html.text | |
type Command | |
= Simple Action | |
| Repeat Int Command | |
type Action | |
= Move | |
command: Parser s Command | |
command = | |
choice [primitive, repetition] | |
primitive: Parser s Command | |
primitive = | |
string "M" $> Simple Move | |
repetition: Parser s Command | |
repetition = | |
let | |
repeatCommand : Parser s Command | |
repeatCommand = | |
int |> andThen what | |
what : Int -> Parser s Command | |
what n = | |
command |> map (Repeat n) | |
in | |
brackets repeatCommand |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This problem is similar to the problems expressed in #7, #14 and #23.
It is resolved by using the
lazy
combinator.