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 8790301
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T22:36:55+00:00 2026-06-13T22:36:55+00:00

This is a function from a parser module. I have trouble understanding one line

  • 0

This is a function from a parser module. I have trouble understanding one line of code

 let rec e1 tokens =
   match tokens with
    Tokenizer.IfTok :: tokens1 -> 
      let (testAST, tokens2) = e1 tokens1
      in
      (match tokens2 with
          Tokenizer.ThenTok :: tokens3 ->
            let (thenAST, tokens4) = e1 tokens3
            in
            (match tokens4 with
                Tokenizer.ElseTok :: tokens5 ->
                  let (elseAST, tokens6) = e1 tokens5 
                  in
                  (If(testAST, thenAST, elseAST), tokens6)
              | _ -> raise (Syntax ("e1: missing else.")))
        | _ -> raise (Syntax ("e1: missing then.")))
  | _ -> e2 tokens

and e2 tokens = ........

I have no idea how this line works

let (testAST, tokens2) = e1 tokens1 in

I know it declares a local variable which is a tuple, but where does the value (testAST, tokens2) come from? It doesn’t seem to have anything to do with tokens or tokens1. Also does this line only declares a tuple or it also calls the function? Thanks!

  • 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-13T22:36:56+00:00Added an answer on June 13, 2026 at 10:36 pm

    Yes, this line does declare two variables and does call the function e1, binding the variables to result of the function call.

    This way of binding variables is called pattern matching. It is based on information about the return type of function e1 – compiler knows it returns a tuple, and then it may be decomposed to parts, and these parts are bound to two new variables, testAST and tokens2 . It is one of most powerful features of FP, which allows you to write much more readable, flexible and brief code.

    It may also be done (matched) on everything if the structure of that entity (pattern) is known to compiler (e.g. case classes in Scala, tuples and lists in Haskell, records in Erlang, etc). Also pattern matching may be used to ignore some parts of the structure that are not relevant for the conditions (e.g. in Haskell if you want to select the second item in three-tuple, just do selectSecond (_, a, _) = a, where _ is special symbol for ignoring values).

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

Sidebar

Related Questions

I'm trying to find out where this function comes from. Any one have any
I call this function from with my code-behind: DeleteFile(Server.MapPath(/) + sitemap_index.xml) Public Shared Function
I don't understand the last line of this function from Programming Perl 3e .
I made this little function from code snippets around the net. It does what
I have a situation where i want to return List<> from this function public
I have a problem where I'm trying to use a function from another module
I am trying to use this function from a COM API which enables the
I'm trying to compile this function from Learn You a Haskell for Great Good
... // result is a JSON data passed to this function from outside var
This is somewhat similiar to this : pthread function from a class But the

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.