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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T12:06:55+00:00 2026-06-17T12:06:55+00:00

I need this function: blubb :: ??? -> Int blubb (n :: Int) =

  • 0

I need this function:

blubb :: ??? -> Int
blubb (n :: Int) = n
blubb (n :: Char) = 42

This is how it should work: the function gets an Int and returns it. If the function gets an Char it returns a constant value and the other cases are indifferent.

Because of the type system in Haskell it might be not possible but I need to get this working …

  • 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-17T12:06:57+00:00Added an answer on June 17, 2026 at 12:06 pm

    This is what type classes are for:

    class Blubb t where
        blubb :: t -> Int
    
    
    instance Blubb Int where
        blubb n = n
    
    instance Blubb Char where
        blubb _ = 42
    

    This overloads blubb to work on both Ints and Chars. The compiler will select the correct one to use based off of the type of the argument.

    However, be careful that you are not using type classes where you actually wanted an Either. You may have actually wanted this:

    blubb :: Either Int Char -> int
    blubb (Left  n) = n
    blubb (Right _) = 42
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to make this function work everywhere, except IE6-7 $(function(){ window.scrollTo(0,300); }) Please
How does PHP's function xmlrpc_encode_request() work? Does it need the value of allow_url_fopen set
I need this function for some personal work and although doing this in general
I need this function to work after the page is loaded. The error is
I am creating a class for an application backbone and I need this function
i'm building this little function, what i need is this query to print me
I need this for calling a C function from Java class (JNI) and I
I have something like this: function showFunction () { // need position and place
I need to export my nodes like this: function recursive_simplify(node){ if(node.children){ for(var i =0;i<node.children.length;i++){
I need to add authentication to this function: function multiRequest($data, $options = array()) {

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.