Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
  • Sign in / Register
  • GHC GHC
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
    • Locked Files
  • Issues 5,244
    • Issues 5,244
    • List
    • Boards
    • Service Desk
    • Milestones
    • Iterations
  • Merge requests 567
    • Merge requests 567
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
    • Test Cases
  • Deployments
    • Deployments
    • Releases
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Code review
    • Insights
    • Issue
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • Glasgow Haskell CompilerGlasgow Haskell Compiler
  • GHCGHC
  • Issues
  • #19936
Closed
Open
Issue created Jun 03, 2021 by David Feuer@treeowlReporter

Odd GND failure/success

There's currently a discussion about whether to change the definition of MonadTrans to use QuantifiedConstraints:

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

I wondered if this works with GND. As it turns out, the answer is yes:

newtype B t (m :: Type -> Type) a => B (t m a)
  deriving (Functor, Applicative, Monad)

-- StandaloneDeriving just to be sure the constraints is
-- what I expect.
deriving instance MonadTrans t => MonadTrans (B t)

compiles just fine. But a conceptually very similar idea does not:

class MonadTrans t where
  lift :: m a -> t m a
  liftMonad :: Monad m => Proxy (t m) -> (Monad (t m) => r) -> r

This one produces an error,

Lift.hs:9:42: error:
    • Occurs check: cannot construct the infinite type: t ~ B t
        arising from the coercion of the method ‘liftMonad’
          from type ‘forall (m :: * -> *) r.
                     Monad m =>
                     Proxy (t m) -> (Monad (t m) => r) -> r’
            to type ‘forall (m :: * -> *) r.
                     Monad m =>
                     Proxy (B t m) -> (Monad (B t m) => r) -> r’
    • When deriving the instance for (MonadTrans (B t))

Why does one work and not the other? Is there a good reason for that, or should they both succeed or both fail?

Edited Jun 03, 2021 by David Feuer
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information
Assignee
Assign to
Time tracking