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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T22:00:39+00:00 2026-05-16T22:00:39+00:00

I would ideally like to write something like this: myValue1 = 1 :: Int

  • 0

I would ideally like to write something like this:

myValue1 = 1 :: Int
myValue2 = 2 :: Int

myFunc :: Int -> Bool
myFunc myValue1 = True
myFunc myValue2 = False

Calling myFunc myValue2 returns True – not what I intend. I know why this happens, but is there a way to express this in Haskell without resorting to C-style #define statements?

  • 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-16T22:00:40+00:00Added an answer on May 16, 2026 at 10:00 pm

    Well, Haskell doesn’t unify names like this. Those new ‘myValue1’ and ‘2’ identifiers are new variables you’re binding.

    The most Haskelly way is to use strong types and pattern matching:

    data Values
       = D1
       | D2
    
    myFunc :: Values -> Bool
    myFunc D1 = True
    myFunc D2 = False
    

    Giving you a static guarantee only “1” or “2” can be passed to myFunc, proper symbolic matching and you even retain conversion to integers by deriving Enum.

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

Sidebar

Related Questions

Ideally I would like intellij to work with this but just getting them to
I would like to setup a multi-tenant ASP.NET MVC app. Ideally, this app would
I am receiving this XML file which I would like to validate. Ideally I
I am trying to write something like this: Pattern p = Pattern.compile(Mar\\w); Matcher m
I would like to animate movement on a SurfaceView . Ideally I would like
I have a route like following, ideally I would like it to match: domain.com/layout/1-slug-is-the-name-of-the-page
and it's linked to a 'confirm comment deleted page. Ideally I would like it
I have an IEnumerable<KeyValuePair<string,string>> , from which I would like, ideally, an anonymous object
In my base class I have a generic method (ideally this would be a
I would like to write a custom web analytics and action tracking solution and

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.