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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T23:44:14+00:00 2026-05-12T23:44:14+00:00

there’s an error I come across all the time but can’t understand how to

  • 0

there’s an error I come across all the time but can’t understand how to make it right. An example of code that gives me this error is:

class Someclass a where
    somefunc :: (Num b) => b -> a -> a

data Sometype = Somecons Int

instance Someclass Sometype where
    somefunc x (Somecons y) = Somecons (x+y)

The error message is:

Couldn’t match expected type ‘b’ against inferred type ‘Int’
‘b’ is a rigid type variable bound by
the type signature for ‘somefunc’ at error.hs:3:21
In the second argument of ‘(+)’, namely ‘y’
In the first argument of ‘Somecons’, namely ‘(x + y)’
In the expression: Somecons (x + y)

I understand that the error message is trying to tell me that I used a name of type Int where he was expecting something with type (Num b) => b. What I can’t understand is that Int fits in (Num b)=>b. Shouldn’t the compiler understand what I’m telling him (that for this specific instance b should be an integer? How can I make this fit?

Coment:
Of course in this specific example I could have made somefunc with type signature:

somefunc :: a -> a-> a 

but supose I wanted something like:

data Newtype = Newcons (Int, Int) 

instance Someclass Newtype where
    somefunc x (Newtype (y,z) ) = Newtype (y+x, z)

Things like that recurrently happens when I’m trying to do something in haskell.

  • 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-12T23:44:14+00:00Added an answer on May 12, 2026 at 11:44 pm

    Well, you can make the point clearer when thinking of the generics notation using universal quantification.

    somefunc :: (Num b) => b -> a -> a
    

    therefore means nothing but

    somefunc :: forall a b . Num b => b -> a -> a
    

    This means your class function must be defined for any numeric b.

    The code

    Data Sometype = Somecons Int
    
    instance Someclass Sometype where
        somefunc x (Somecons y) = Somecons (x+y)
    

    forces b to have one concrete type – Int, which doesn’t conform with the requirement to work for any numeric type.

    You might want to have something like this

    class Num b => SomeClass a b where
        somefunc :: b -> a -> a
    
    instance Someclass Somecons Int where
        -- ...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

There was a smbmrx sample code using RDBSS in WDK Vista. But since WDK
There are a lot of example implementations of daemons on the net. Most that
There are some Magento Connect extensions that I find myself installing every time I
There are some stdlib functions that throw errors on invalid input. For example: Prelude>
There is my code that I want to alert test once when mousemove ,
There's a lot of reading on self referencing problems, but I can't seem to
There is a moment in my app, that I need to force to show
There is a column that exists in 2 tables. In table 1, this column
There's a Rails 3.2.3 web application which doesn't use any database. But in spite
There are nice SO question and answers about this issue, but these options didn't

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.