Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Applicative yields SOE where Monad does not #26

Open
dashkal16 opened this issue Feb 12, 2016 · 1 comment
Open

Applicative yields SOE where Monad does not #26

dashkal16 opened this issue Feb 12, 2016 · 1 comment

Comments

@dashkal16
Copy link

Current import: "org.tpolecat" %% "atto-core" % "0.4.2"

Example code:

lazy val exprBad: Parser[Int] = eParensBad | eLiteralInt
lazy val eParensBad: Parser[Int] = char('(') *> many(whitespace) *> exprBad <* many(whitespace) <* char(')')

lazy val exprGood: Parser[Int] = eParensGood | eLiteralInt
lazy val eParensGood: Parser[Int] = {
  for {
    _ <- char('(')
    _ <- many(whitespace)
    e <- exprGood
    _ <- many(whitespace)
    _ <- char(')')
  } yield (e)
}

lazy val eLiteralInt: Parser[Int] = int

def makeItCrash = exprBad.parse("5").done
def worksFine = exprGood.parse("5").done

scala> worksFine
res0: atto.ParseResult[Int] = Done(,5)
scala> makeItCrash
java.lang.StackOverflowError
  <stacktrace bouncing between exprBad and eParensBad>
@dashkal16
Copy link
Author

Note: Switching from *> to ~> also avoids the stack overflow.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant