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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T06:47:43+00:00 2026-06-11T06:47:43+00:00

Classic way to define Haskell functions is f1 :: String -> Int f1 (‘-‘

  • 0

Classic way to define Haskell functions is

f1 :: String -> Int
f1 ('-' : cs) -> f1 cs + 1
f1 _ = 0

I’m kinda unsatisfied writing function name at every line. Now I usually write in the following way, using pattern guards extension and consider it more readable and modification friendly:

f2 :: String -> Int
f2 s
  | '-' : cs <- s = f2 cs + 1
  | otherwise = 0

Do you think that second example is more readable, modifiable and elegant? What about generated code? (Haven’t time to see desugared output yet, sorry!). What are cons? The only I see is extension usage.

  • 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-11T06:47:45+00:00Added an answer on June 11, 2026 at 6:47 am

    I prefer writing function name when I am pattern matching on something as is shown in your case. I find it more readable.

    I prefer using guards when I have some conditions on the function arguments, which helps avoiding if else, which I would have to use if I was to follow the first pattern.

    So to answer your questions

    Do you think that second example is more readable, modifiable and elegant?
    

    No, I prefer the first one which is simple and readable. But more or less it depends on your personal taste.

    What about generated code?
    

    I dont think there will be any difference in the generated code. Both are just patternmatching.

    What are cons? 
    

    Well patternguards are useful to patternmatch instead of using let or something more cleanly.

    addLookup env var1 var2
       | Just val1 <- lookup env var1
       , Just val2 <- lookup env var2
       = val1 + val2
    

    Well the con is ofcourse you need to use an extension and also it is not Haskell98 (which you might not consider much of a con)

    On the other hand for trivial pattern matching on function arguments I will just use the first method, which is simple and readable.

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

Sidebar

Related Questions

Is there a way to enabling collapsing of functions and sub-routines for Classic ASP
Is there a way to have ASP classic cdonts email, have an file attached
I've finally found a way to debug classic asp code in visual studio 2008
Writing Classic ASP code in JScript has a lot going for it: more humane
I have a classic HTML select box: Show: <select name=show id=showThreads> <option value=all selected=selected>All</option>
i'm lookin for a way to make some kind of function into php and
I'm working my way through the online MIT lectures for the classic 6.001 course:
What is the best way to save data in session variables in a classic
Is there a way to mark classic ASP ASPSESSIONID* cookies as secure? It appears
Is there a way to upload an image using flex inbuild .browse() and classic

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.