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

  • SEARCH
  • Home
  • 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 8682117
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T21:41:06+00:00 2026-06-12T21:41:06+00:00

I asked a question similar to this earlier, and had the original question resolved.

  • 0

I asked a question similar to this earlier, and had the original question resolved. I have run into an additional problem that was hidden by the other error. I am able to make statements like “if” statements work properly, but not a “while” statement. When a “stmt” is evaluated, the environment must be updated. This works properly for my “if” statement like this:

exec :: Env -> Stmt -> Env
exec env (If c t e) = 
    exec env ( if eval env c == BoolLit True then t else e )

eval Looks like this:

eval :: Env -> Expr -> Expr
eval _ (IntLit i) = IntLit i
eval _ (BoolLit b) = BoolLit b
eval env (Var n) = lookupVar env n
eval env (BinOp op a b) = primEval op (eval env a) (eval env b)

The file being parsed looks like this:

x = 1; c = 0;
if (x < 2) c = c + 1; else ;

My attempt to have the while statement working is done like this:

exec env (While c t) = exec env ( if eval env c == BoolLit True then t)

But this gives a parse error on ‘)’. The expected format of the while statement in the file being parsed:

x = 1; c = 1;
while (x < 10)
{
  c = c * x;
  x = x + 1;
}
c

I’m trying to understand how I can return the proper environment based on this expected format. It would be simple if there were already a similar structure for while statements in Haskell, but nothing exists like this that I am aware of.

  • 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-12T21:41:07+00:00Added an answer on June 12, 2026 at 9:41 pm

    You are missing an else clause in your function, it should probably be:

    exec env (While c t) = if eval env c == BoolLit True then exec env t else env
    

    To actually make it work, that is to execute the body multiple times:

    exec env (While c t) = if   eval env c == BoolLit True 
                           then exec (exec env t) (While c t)
                           else env
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have already asked a similar question earlier but I have notcied that I
This is similar to a question I asked earlier . The answers to that
i have asked a similar question earlier, but this time i need a method
I had asked a question similar to this before, but I have a new
This is a similar question I asked earlier, except different in the fact that
This question is very similar to an earlier question I asked ( This Question
I have asked a question similar to this in the past but this is
I had asked a question very much similar to this in the thread: https://stackoverflow.com/questions/11259474/store-the-numericals-in-char-array-into-an-integer-variable-in-vc
This is similar to a question that has already been asked. However, I am
Guys I asked a similar question like this earlier since I was unable to

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.