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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T01:50:36+00:00 2026-06-18T01:50:36+00:00

Playing with Haskell’s typeclasses I created an instance of a typeclass of a list,

  • 0

Playing with Haskell’s typeclasses I created an instance of a typeclass of a list, whose elements are not an instance of that typeclass:

class Three a where
    three :: a -> [a]

instance (Three a) => Three [a] where
    three x = [x, x, x]

I get a different error message for a list of Integers and for a list of Chars:

Chars

*Main> three ['c']

<interactive>:11:1:
    No instance for (Three Char)
      arising from a use of `three'
    Possible fix: add an instance declaration for (Three Char)
    In the expression: three ['c']
    In an equation for `it': it = three ['c']

Integers

*Main> three [1, 2]

<interactive>:12:8:
    Ambiguous type variable `t0' in the constraints:
      (Num t0) arising from the literal `1' at <interactive>:12:8
      (Three t0) arising from a use of `three' at <interactive>:12:1-5
    Probable fix: add a type signature that fixes these type variable(s)
    In the expression: 1
    In the first argument of `three', namely `[1, 2]'
    In the expression: three [1, 2]

Why??

(Now, the error for Chars is understood – there is no instance for it. But the ambiguity error for Integers is not clear to me. I thought that maybe that’t because integers are already an instance of something (Num) so I created another arbitrary typeclass and an instance of it for Char, but got the same error for Char as before).

I’ll appreciate your help

  • 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-18T01:50:37+00:00Added an answer on June 18, 2026 at 1:50 am

    The first error points out that there is no instance for Three for Char. As you say, easy!

    However, in the second case, since the type of your numeric literals is unknown/polymorphic, GHC can’t tell if there is an instance for them or not. Hence, the error isn’t about a missing instance, but an ambiguous variable.

    You could, for example, have valid instances for Three for both Int and Double. How would GHC know which to pick?

    (ignoring extended defaulting, that is).

    So the error is different, because the type of error actually is different.

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

Sidebar

Related Questions

I'm playing around in Haskell to try and get the hang of it. I'm
I have been playing around with haskell and I found out that if I
I noticed as I was playing around with Haskell today that it is possible
When playing with various algorithms in Haskell it often happens to me that I
I've been playing around with Scalaz to get a little bit of the haskell
I'm playing around with Haskell at the moment and thus stumbled upon the list
I was playing around with typeclasses and made this: class Firstable f where fst
I started playing with Haskell and I use Vim. I have autoindent on in
After playing around with haskell a bit I stumbled over this function: Prelude Data.Maclaurin>
I am currently playing around with Haskell basics and stumbled upon the following use

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.