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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T02:57:49+00:00 2026-05-18T02:57:49+00:00

I often hear the phrase, guards are just syntactic sugar for if-then-else (or case

  • 0

I often hear the phrase, guards are just syntactic sugar for if-then-else (or case statements).

Can somebody please desugar the following instance:

halfOf :: Int -> Int
halfOf x | even x = div x 2

(The function is intentionally partial)

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-05-18T02:57:49+00:00Added an answer on May 18, 2026 at 2:57 am

    The semantics of pattern matching are defined in the following section of the standard: Formal Semantics of Pattern Matching.

    The step that is relevant to your question is c. As you can see, pattern matches with guards of the form

    case v of { p | g1 -> e1 ; ...
                  | gn -> en where { decls }
                _     -> e' }
    

    Are translated to pattern matches without guards as:

    case e' of
    {y ->
       case v of {
           p -> let { decls } in
                if g1 then e1 ... else if gn then en else y ;
            _ -> y }}
    

    So pattern guards are defined in terms of if and “fallthrough” is implemented by binding the expression to a variable and then repeating it once in the else clause of the if and then in the pattern that you’d fall through to.

    If there is no case to fall through to (as in your example) one will have been inserted by step b, which inserts a default case _ -> error "No match"

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

Sidebar

Related Questions

I often hear things like Can we load our employee info using LDAP? Yet,
I often hear that mongodb can perform atomicity at one collection level. Do you
I often hear people complain how expensive MATLAB licenses are. Then I wonder why
I hear this phrase often and do not fully understand it's meaning. What does
In Groovy++ I often hear of the term Annotations. Can anyone explain me what
I often hear around here from test driven development people that having a function
I often hear complaints that programming languages that make heavy use of symbols for
I often hear a Model must be wrapped by a ViewModel that the View
I often hear about eventual consistency in different speeches about NoSQL, data grids etc.
Often hear about curve modeled using spline. What's the advantage of using spline?

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.