[GHC] #9196: Higher-rank constraint treated as type instead

#9196: Higher-rank constraint treated as type instead ------------------------------------+------------------------------------- Reporter: goldfire | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.8.2 Keywords: | Operating System: Unknown/Multiple Architecture: Unknown/Multiple | Type of failure: None/Unknown Difficulty: Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | ------------------------------------+------------------------------------- When I say {{{ {-# LANGUAGE RankNTypes #-} module Bug where class P z foo :: (forall b. P (a, b)) => a -> a foo x = x }}} I get {{{ Bug.hs:7:9: Couldn't match expected type ‘a -> a’ with actual type ‘P (a, b0)’ Relevant bindings include x :: forall b. P (a, b) (bound at Bug.hs:7:5) foo :: (forall b. P (a, b)) -> a -> a (bound at Bug.hs:7:1) In the expression: x In an equation for ‘foo’: foo x = x }}} I expected my code to be rejected, but not with that error message. It seems that GHC thinks `forall b. P (a, b))` has kind `*`, not kind `Constraint`. Encountered while experimenting with #9195. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/9196 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#9196: Higher-rank constraint treated as type instead -------------------------------------+------------------------------------ Reporter: goldfire | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.8.2 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Unknown/Multiple Type of failure: None/Unknown | Difficulty: Unknown Test Case: | Blocked By: Blocking: | Related Tickets: -------------------------------------+------------------------------------ Comment (by archblob): I simplified this a little bit, you just need an explicit `forall` and parentheses. This works: {{{ foo :: forall a. P a => a -> a }}} This does not: {{{ foo :: (forall a. P a) => a -> a }}} -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/9196#comment:1 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#9196: Higher-rank constraint treated as type instead -------------------------------------+------------------------------------ Reporter: goldfire | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.8.2 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Unknown/Multiple Type of failure: None/Unknown | Difficulty: Unknown Test Case: | Blocked By: Blocking: | Related Tickets: -------------------------------------+------------------------------------ Comment (by archblob): Experimenting with this I found that ghc will go along with `foo :: a -> ((forall b. P b) => b) -> a` and transform it in `foo :: a -> ((forall b. P b) -> b) -> a`. I may have a simple fix for this, just a check for foralls when typechecking a context. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/9196#comment:2 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#9196: Higher-rank constraint treated as type instead -------------------------------------+------------------------------------ Reporter: goldfire | Owner: Type: bug | Status: patch Priority: normal | Milestone: Component: Compiler | Version: 7.8.2 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Unknown/Multiple Type of failure: None/Unknown | Difficulty: Unknown Test Case: | Blocked By: Blocking: | Related Tickets: -------------------------------------+------------------------------------ Changes (by archblob): * status: new => patch -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/9196#comment:3 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#9196: Higher-rank constraint treated as type instead -------------------------------------+------------------------------------ Reporter: goldfire | Owner: Type: bug | Status: patch Priority: normal | Milestone: Component: Compiler | Version: 7.8.2 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Unknown/Multiple Type of failure: None/Unknown | Difficulty: Unknown Test Case: | Blocked By: Blocking: | Related Tickets: -------------------------------------+------------------------------------ Comment (by archblob): The patch passes validation and I hope I understood the problem, even if that's not the case, at least I got to learn something new. Even though the pathological type construction can be detected and stopped earlier when checking the type and transforming from HsType to Type, doing so would yeild very bad error message, so the patch checks for a bad type in `check_valid_type` where the check for the same illegal types happens for classes. Even so, the type is not printed as the user wrote it, and this could be a source of confusion. This could be fixed by considering `ForAllTy` in `isPredTy`, but this will brake code because even though in the comments about `isPredTy` it is said that it is only used for printing, I found it used in places not concerning pretty printing. Even used it in tis patch :-P. Maybe there should really be a variation of this function that is only used for pretty printing. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/9196#comment:4 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#9196: Higher-rank constraint treated as type instead -------------------------------------+------------------------------------ Reporter: goldfire | Owner: Type: bug | Status: patch Priority: normal | Milestone: 7.10.1 Component: Compiler | Version: 7.8.2 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Unknown/Multiple Type of failure: None/Unknown | Difficulty: Unknown Test Case: | Blocked By: Blocking: | Related Tickets: -------------------------------------+------------------------------------ Changes (by archblob): * milestone: => 7.10.1 -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/9196#comment:5 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#9196: Higher-rank constraint treated as type instead
-------------------------------------+------------------------------------
Reporter: goldfire | Owner:
Type: bug | Status: patch
Priority: normal | Milestone: 7.10.1
Component: Compiler | Version: 7.8.2
Resolution: | Keywords:
Operating System: Unknown/Multiple | Architecture: Unknown/Multiple
Type of failure: None/Unknown | Difficulty: Unknown
Test Case: | Blocked By:
Blocking: | Related Tickets:
-------------------------------------+------------------------------------
Comment (by Simon Peyton Jones

#9196: Higher-rank constraint treated as type instead ------------------------------------------------+-------------------------- Reporter: goldfire | Owner: Type: bug | Status: closed Priority: normal | Milestone: 7.10.1 Component: Compiler | Version: 7.8.2 Resolution: fixed | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: None/Unknown | Unknown/Multiple Test Case: typecheck/should_fail/T9196 | Difficulty: Blocking: | Unknown | Blocked By: | Related Tickets: ------------------------------------------------+-------------------------- Changes (by simonpj): * status: patch => closed * testcase: => typecheck/should_fail/T9196 * resolution: => fixed -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/9196#comment:7 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#9196: Higher-rank constraint treated as type instead ------------------------------------------------+-------------------------- Reporter: goldfire | Owner: Type: bug | Status: closed Priority: normal | Milestone: 7.10.1 Component: Compiler | Version: 7.8.2 Resolution: fixed | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: None/Unknown | Unknown/Multiple Test Case: typecheck/should_fail/T9196 | Difficulty: Blocking: | Unknown | Blocked By: | Related Tickets: 9301 ------------------------------------------------+-------------------------- Changes (by heisenbug): * related: => 9301 -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/9196#comment:8 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler
participants (1)
-
GHC