Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8415641
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T01:30:12+00:00 2026-06-10T01:30:12+00:00

void whatever() { // … val parser = new MyParser val parse = parser.parse(input)

  • 0
void whatever() {
  // ...
  val parser = new MyParser
  val parse = parser.parse(input)
  if (parse successful) {
    semanticAnalysis(parse)
  }
}

void semanticAnalysis(parse: DontKnowTheCorrectType) {
  // ...
}

What type do I have to give to the formal parameter parse? Hovering over parse inside whatever says val parse: parser.ParseResult[parsing.Program], but of course that doesn’t work as a parameter type of semanticAnalysis, because the local variable parse is not in scope there.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T01:30:14+00:00Added an answer on June 10, 2026 at 1:30 am

    Parse results are path-dependent types because they are results of this specific parser and there’s no guarantee they are compatible.

    This is why parsers are usually not instantiated the way you use them (new MyParser), but as object.

    object MyParser extends RegexParsers { 
       def statements : Parser[List[Statement]] = // ...
    } 
    
    def handleResult(res: MyParser.ParseResult[List[Statement]]) = { // ... } 
    
    val res = MyParser.parseAll(MyParser.statements, "/* */")
    

    If you need more dynamic behaviour (or want concurrent parsing, parser combinators aren’t thread-safe, ouch), you’ll just have to keep the parser object accessible (and stable) wherever you want to use its results.

    Sadly, passing a parser and its result around together is not trivial because you run into the prohibition of dependent method types, e.g.

      def fun(p: scala.util.parsing.combinator.Parsers, res: p.ParseResult[_]) = {}
    

    won’t compile (“illegal dependent method type”), but there are ways to get around that if you must, like the answer to this question.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Suppose I have: void function1( Type* object ); //whatever implementation void function2( Type& object
I have this code : private void insertValus() { ContentValues initialValues = new ContentValues();
Imagine you have an aspect: @Aspect public class MyAspect { @Pointcut(whatever) public void anyAnnotation()
If I have a class like this: public class Whatever { public void aMethod(int
Can i write sin(whatever) in Java and have it work? public static void main(String[]
Let's say I have a function, taking an rvalue reference: void whatever (std::unique_ptr<int>&&) {
private void CellFormatting(object sender, DataGridViewCellFormattingEventArgs e) { if(whatever) e.CellStyle.BackColor = SystemColors.ControlDark; This works fine
For instance, write a function such as: void foo() { try { throw new
I have an interface thus: public interface Doer { public void do(Object arg); }
Say you have 2 functions: void func(int x,int y,...) { //do stuff } void

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.