[GHC] #14733: Won't use (forall xx. f xx) with -XQuantifiedConstraints

GHC ghc-devs at haskell.org
Wed Jan 31 14:59:39 UTC 2018


#14733: Won't use (forall xx. f xx) with -XQuantifiedConstraints
-------------------------------------+-------------------------------------
        Reporter:  Iceland_jack      |                Owner:  (none)
            Type:  bug               |               Status:  new
        Priority:  normal            |            Milestone:
       Component:  Compiler          |              Version:  8.5
      Resolution:                    |             Keywords:
                                     |  QuantifiedConstraints, wipT2893
Operating System:  Unknown/Multiple  |         Architecture:
                                     |  Unknown/Multiple
 Type of failure:  None/Unknown      |            Test Case:
      Blocked By:                    |             Blocking:
 Related Tickets:                    |  Differential Rev(s):
       Wiki Page:                    |
-------------------------------------+-------------------------------------

Comment (by Iceland_jack):

 Only moderate? ;-) I have listed some things this rules out as Phabricator
 comments:

 * ([https://phabricator.haskell.org/D4353#121416 Phab]) A (categorical)
 vocabulary for constraints: `uncurry :: (a => b => c) :- ((a, b) => c)`
 * ([https://phabricator.haskell.org/D4353#121383 Phab]) Defining `(>>=)
 @(Free cls)` needs a `cls` instance for `Free cls b` but it can't range
 over `b`.
   {{{#!hs
 newtype Free cls a = Free (forall xx. cls xx => (a -> xx) -> xx)

 bind :: cls (Free cls b) => Free cls a -> (a -> Free cls b) -> Free cls b
 bind (Free free) f = free f
   }}}
   Instead:
   {{{#!hs
 instance (forall xx. cls (Free cls xx)) => Monad (Free cls)
   }}}
 * ([https://phabricator.haskell.org/D4353#121403 Phab]) Works: but what we
 really want is an instance of `Free mon` for any `forall xx. Monoid xx =>
 mon xx`
   {{{#!hs
 instance Foldable (Free Monoid) where
   foldMap :: Monoid m => (a -> m) -> (Free Monoid a -> m)
   foldMap f (Free free) = free f

 instance Foldable (Free Monoid) where
   foldMap :: Monoid m => (a -> m) -> (Free Monoid a -> m)
   foldMap f (Free free) = free f
   }}}

 Your `class f a => C f a` solution didn't work for me (using latest
 version): here is my
 [https://gist.github.com/Icelandjack/6b42e7e19c7f130f2ca947495e09ca54 full
 code and error messages].

 Echoing Sjoerd if there is a mechanical translation `class f a => C f a`
 can GHC do it?

-- 
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/14733#comment:6>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler


More information about the ghc-tickets mailing list