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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T14:23:02+00:00 2026-06-15T14:23:02+00:00

I’m building a call by name Haskell interpreter and I want to implement a

  • 0

I’m building a call by name Haskell interpreter and I want to implement a function short :: Val -> Exp -> Error Val that will evaluate a value applied to an expression. I don’t want to evaluate the second arguments of the short-circuited boolean binary operators (i.e. ((&&) False) and ((||) True)), nor the argument passed to a unit lambda (\() -> ...) abstraction.

In a lazy language such as Haskell, I know you get short circuited boolean binary operators built into the Prelude. I was thinking that its possible to do something like this:

short :: Val -> Exp -> Error Val
short (Partial (&&) False) = False
-- Making use of Partial Oper Val that is defined in Val

But I already know that a type error will arise. I’m not sure what to exactly do. Any suggestions?

Some additional definitions:

data Val = VUnit | VNil
         | VN Int | VB Bool | VOp Oper
         | Partial Oper Val
         | VLamUnit Exp (Env Val)
         | VLam String Exp (Env Val)
         | VListBool [Bool]
         | VListInt [Int]

data Exp = Unit | Nil
         | N Int | B Bool | Var String | Op Oper
         | App Exp Exp
         | LamUnit Exp
         | Lam String Exp
         | If Exp Exp Exp
         | Let [(String, Exp)] Exp

data Error a = S a
             | Error String
  • 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-15T14:23:04+00:00Added an answer on June 15, 2026 at 2:23 pm

    The evaluation of the arguments of a function is first determined by the patterns used to bind the arguments.

    If you have

    short :: Val -> Exp -> Error Val
    short val ex
       | condition on val only       = something
       | other condition on val only = somethingElse
       | condition involving ex too  = thirdPossibility
       | otherwise                   = whatever
    

    no evaluation takes place on binding the arguments, since the patterns are irrefutable variable patterns, val is – partially or maybe completely – evaluated to determine the outcome of the first guard. If that evaluates to True, exp is only evaluated if it is used in something and its evaluation is necessary to evaluate something. Only if the first two conditions evaluate to False, ex is evaluated to determine the value of the third guard (and maybe not even then).

    If you can shortcut based on the constructor of val, you can use a refutable pattern for val and let ex be a variable pattern (just an identifier), you get the same short-circuiting as for (&&) etc.

    short (Val foo) ex = Okay (foo bar ex)
    short (Lav oof) _  = Okay oof
    short val ex
      | isGood val = oomph
      | isBad ex   = error "Didn't expect that"
      | otherwise  = undefined
    

    If you don’t use the Exp argument on the right hand side, you don’t even need to give it a name, the wildcard _ says “here is an argument that shall be ignored”.

    For your desired behaviour of

    short :: Val -> Exp -> Error Val
    short (Partial (&&) False) = False
    

    that as such doesn’t work because False is a Bool and not a Val, you can use

    short (Partial OR (VB False)) _ = S False
    

    with a hypothetical constructor OR of Oper. (You can use (&&) there, but that is a variable pattern matching anything.) That pattern doesn’t even bind the Exp argument, so unless its evaluation has been forced by previous equations for short, it remains unevaluated.

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

Sidebar

Related Questions

I need a function that will clean a strings' special characters. I do NOT
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I want to construct a data frame in an Rcpp function, but when I
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but
I've got a string that has curly quotes in it. I'd like to replace
I have a small JavaScript validation script that validates inputs based on Regex. I

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.