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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T19:12:26+00:00 2026-05-25T19:12:26+00:00

Can anyone explain this error: Syntax error in instance head (constructor expected) class Nullable

  • 0

Can anyone explain this error:

Syntax error in instance head (constructor expected)

class Nullable v where
  default_val :: v


instance Num a => Nullable a where  -- error reported here
  default_val = 0::a

Thanks

  • 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-25T19:12:27+00:00Added an answer on May 25, 2026 at 7:12 pm

    First off, hackage has you covered.

    Secondly, don’t write instances of the form

    instance OtherClass a => Class a where
    

    they don’t work like you want. (YMMV with compilers other than GHC, but I can’t see that it’s a good idea even then). Presumably your intent is to create several instances, something like:

    instance Num a => Nullable a where  -- error reported here
      default_val = 0::a
    
    instance Bounded a => Nullable a where
      default_val = minBound
    

    You can think of type class constraints as an extra argument to a function, like this:

    instance Num a => Nullable a where
      default_val = NumDict a -> 0::a
    
    instance Bounded a => Nullable a where
      default_val = BoundedDict a -> minBound
    

    Then ghc actually sees these class instances like this:

    instance Nullable a where
      default_val = NumDict a -> 0::a
    
    instance Nullable a where
      default_val = BoundedDict a -> minBound
    

    Now, which instance should the compiler choose? There are two instances that both claim to be valid for all types. So there’s a compiler error.

    This is a problem even if you one have one type class based instance. Suppose that you have these instances:

    instance Num a => Nullable a where
      default_val = 0::a
    
    instance Nullable String where
      default_val = ""
    
    instance Nullable BS.ByteString where
      default_val = BS.empty
    

    The first is still considered valid for all types, so ghc says that it needs the OverlappingInstances extension to use them all. That’s not entirely evil. But when you try to make any use of this, before long ghc will require another extension, IncoherentInstances.

    Lots of people are afraid to use UndecidableInstances, but that fear is misplaced. The worst that can happen with UndecidableInstances is that compiling won’t terminate (but it usually does). IncoherentInstances is the extension which should inspire fear, as it will bring doom upon your code. If GHC says that you have to enable IncoherentInstances, it means you need to change your code.

    tl;dr

    Don’t write instances of the form

    instance OtherClass a => Class a where
    

    They don’t do what you want.

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

Sidebar

Related Questions

Can anyone explain to me why i get this error: Parse error: syntax error,
Can anyone explain what might be causing this error. Im thinking its the quotes.
Can anyone explain why this code gives the error: error C2039: 'RT' : is
Can anyone explain why I'm getting this compile error? Duplicate 'Rad.Core.Aop.MethodArgumentValidation' attribute E:\Scripting\Rad.Core\Properties\AssemblyInfo.cs This
Can anyone explain this error? It works fine if I use [equipment valueForKey:@name]; or
Can anyone explain a parse error like this one: Method 'get_EnableCdn' in type 'System.Web.UI.ScriptManager'
Can anyone explain what this mod_rewrite rule is doing? I'm trying to comment the
Can anyone explain why this code with the given routes returns the first route?
Can anyone explain why this query returns an empty result. SELECT * FROM (`bookmarks`)
Can anyone explain to me what this means? Run-Time Check Failure #0 - The

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.