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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T17:41:52+00:00 2026-06-12T17:41:52+00:00

I’ve heard that there are some problems with Haskell’s broken constraint system, as of

  • 0

I’ve heard that there are some problems with Haskell’s “broken” constraint system, as of GHC 7.6 and below. What’s “wrong” with it? Is there a comparable existing system that overcomes those flaws?

For example, both edwardk and tekmo have run into trouble (e.g. this comment from tekmo).

  • 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-12T17:41:53+00:00Added an answer on June 12, 2026 at 5:41 pm

    Ok, I had several discussions with other people before posting here because I wanted to get this right. They all showed me that all the problems I described boil down to the lack of polymorphic constraints.

    The simplest example of this problem is the MonadPlus class, defined as:

    class MonadPlus m where
        mzero :: m a
        mplus :: m a -> m a -> m a
    

    … with the following laws:

    mzero `mplus` m = m
    
    m `mplus` mzero = m
    
    (m1 `mplus` m2) `mplus` m3 = m1 `mplus` (m2 `mplus` m3)
    

    Notice that these are the Monoid laws, where the Monoid class is given by:

    class Monoid a where
        mempty :: a
        mappend :: a -> a -> a
    
    mempty `mplus` a = a
    
    a `mplus` mempty = a
    
    (a1 `mplus` a2) `mplus` a3 = a1 `mplus` (a2 `mplus` a3)
    

    So why do we even have the MonadPlus class? The reason is because Haskell forbids us from writing constraints of the form:

    (forall a . Monoid (m a)) => ...
    

    So Haskell programmers must work around this flaw of the type system by defining a separate class to handle this particular polymorphic case.

    However, this isn’t always a viable solution. For example, in my own work on the pipes library, I frequently encountered the need to pose constraints of the form:

    (forall a' a b' b . Monad (p a a' b' b m)) => ...
    

    Unlike the MonadPlus solution, I cannot afford to switch the Monad type class to a different type class to get around the polymorphic constraint problem because then users of my library would lose do notation, which is a high price to pay.

    This also comes up when composing transformers, both monad transformers and the proxy transformers I include in my library. We’d like to write something like:

    data Compose t1 t2 m r = C (t1 (t2 m) r)
    
    instance (MonadTrans t1, MonadTrans t2) => MonadTrans (Compose t1 t2) where
        lift = C . lift . lift
    

    This first attempt doesn’t work because lift does not constrain its result to be a Monad. We’d actually need:

    class (forall m . Monad m => Monad (t m)) => MonadTrans t where
        lift :: (Monad m) => m r -> t m r
    

    … but Haskell’s constraint system does not permit that.

    This problem will grow more and more pronounced as Haskell users move on to type constructors of higher kinds. You will typically have a type class of the form:

    class SomeClass someHigherKindedTypeConstructor where
        ...
    

    … but you will want to constrain some lower-kinded derived type constructor:

    class (SomeConstraint (someHigherKindedTypeConstructor a b c))
        => SomeClass someHigherKindedTypeConstructor where
        ...
    

    However, without polymorphic constraints, that constraint is not legal. I’ve been the one complaining about this problem the most recently because my pipes library uses types of very high kinds, so I run into this problem constantly.

    There are workarounds using data types that several people have proposed to me, but I haven’t (yet) had the time to evaluate them to understand which extensions they require or which one solves my problem correctly. Somebody more familiar with this issue could perhaps provide a separate answer detailing the solution to this and why it works.

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

Sidebar

Related Questions

I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I know there's a lot of other questions out there that deal with this
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I have a small JavaScript validation script that validates inputs based on Regex. I
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace

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.