I have this mini parser for add expression. But compiler overflows due to the recursive structure. I saw lazy seems to be the solution for this but can't figure out why it doesn't work.
term : Parser Utf8 U64
term = alt digits (lazy (\_ -> expr) |> between (codeunit '(') (codeunit ')'))
expr : Parser Utf8 U64
expr = const (\x -> \y -> x + y) |> apply (lazy \_ -> term) |> skip (codeunit '+') |> apply (lazy \_ -> term)
expect parseStr expr "1+2" == Ok 3u64
expect parseStr expr "1+(1+2)" == Ok 4u64
I have this mini parser for add expression. But compiler overflows due to the recursive structure. I saw
lazyseems to be the solution for this but can't figure out why it doesn't work.