[GHC] #13600: surprising error message with bang pattern

#13600: surprising error message with bang pattern -------------------------------------+------------------------------------- Reporter: andrewufrank | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.0.2 Keywords: | Operating System: Linux Architecture: x86_64 | Type of failure: Poor/confusing (amd64) | error message Test Case: | Blocked By: Blocking: | Related Tickets: Differential Rev(s): | Wiki Page: -------------------------------------+------------------------------------- the following code {{{ f3 :: [Int] -> IO Int f3 x = return (sum x) f4 :: [Int] -> IO Int f4 !x = return (sum x) }}} gives `The type signature for ‘f4’ lacks an accompanying binding` for the second function (the two functions are exactly the same except for the added bang). I do not understand bang patterns well, but would expect a more instructive error message. without the type definition, the second function f4 compiles with the bang). -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13600 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13600: surprising error message with bang pattern -------------------------------------+------------------------------------- Reporter: andrewufrank | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.0.2 Resolution: | Keywords: Operating System: Linux | Architecture: x86_64 Type of failure: Poor/confusing | (amd64) error message | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by mpickering): You need to turn on the `BangPatterns` extension, otherwise you are defining an infix operator `!`. The error message is then accurate as you have given a type signature for `f4` but then defined `!`. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13600#comment:1 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13600: surprising error message with bang pattern -------------------------------------+------------------------------------- Reporter: andrewufrank | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.0.2 Resolution: | Keywords: Operating System: Linux | Architecture: x86_64 Type of failure: Poor/confusing | (amd64) error message | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by simonpj): Ha ha, Matthew is right! Maybe it would help if, when GHC sees an infix definition for `(!)`, and the `!` immediately precedes the second argument, we suggested the possibility of bang patterns? To suppress the warning, we'd suggest adding a space, thus {{{ f4 ! x = ... }}} I think that'd be useful, if someone wants to try. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13600#comment:2 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13600: surprising error message with bang pattern -------------------------------------+------------------------------------- Reporter: andrewufrank | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.0.2 Resolution: | Keywords: Operating System: Linux | Architecture: x86_64 Type of failure: Poor/confusing | (amd64) error message | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by andrewufrank): Thank you very much for the clarification. As i said, i have not much experience with bang patterns and did not see in the manual the hint that I would have to turn on an extension. Perhaps somebody could revise the relevant parts of the ghc docs. andrew -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13600#comment:3 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13600: surprising error message with bang pattern -------------------------------------+------------------------------------- Reporter: andrewufrank | Owner: sighingnow Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.0.2 Resolution: | Keywords: Operating System: Linux | Architecture: x86_64 Type of failure: Poor/confusing | (amd64) error message | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by sighingnow): * owner: (none) => sighingnow -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13600#comment:4 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13600: surprising error message with bang pattern -------------------------------------+------------------------------------- Reporter: andrewufrank | Owner: sighingnow Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.0.2 Resolution: | Keywords: BangPatterns Operating System: Linux | Architecture: x86_64 Type of failure: Poor/confusing | (amd64) error message | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by ulysses4ever): * keywords: => BangPatterns -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13600#comment:5 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13600: surprising error message with bang pattern -------------------------------------+------------------------------------- Reporter: andrewufrank | Owner: sighingnow Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.0.2 Resolution: | Keywords: BangPatterns Operating System: Unknown/Multiple | Architecture: Type of failure: Poor/confusing | Unknown/Multiple error message | Test Case: Blocked By: | Blocking: Related Tickets: #15166, #15458 | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by RyanGlScott): * os: Linux => Unknown/Multiple * architecture: x86_64 (amd64) => Unknown/Multiple * related: => #15166, #15458 -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13600#comment:6 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13600: surprising error message with bang pattern -------------------------------------+------------------------------------- Reporter: andrewufrank | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.0.2 Resolution: | Keywords: BangPatterns Operating System: Unknown/Multiple | Architecture: Type of failure: Poor/confusing | Unknown/Multiple error message | Test Case: Blocked By: | Blocking: Related Tickets: #15166, #15458 | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by sighingnow): * owner: sighingnow => (none) -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13600#comment:7 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13600: surprising error message with bang pattern -------------------------------------+------------------------------------- Reporter: andrewufrank | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.0.2 Resolution: | Keywords: BangPatterns, | newcomer Operating System: Unknown/Multiple | Architecture: Type of failure: Poor/confusing | Unknown/Multiple error message | Test Case: Blocked By: | Blocking: Related Tickets: #15166, #15458 | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by RyanGlScott): * keywords: BangPatterns => BangPatterns, newcomer -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13600#comment:8 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13600: surprising error message with bang pattern -------------------------------------+------------------------------------- Reporter: andrewufrank | Owner: v0d1ch Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.0.2 Resolution: | Keywords: BangPatterns, | newcomer Operating System: Unknown/Multiple | Architecture: Type of failure: Poor/confusing | Unknown/Multiple error message | Test Case: Blocked By: | Blocking: Related Tickets: #15166, #15458 | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by v0d1ch): * owner: (none) => v0d1ch -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13600#comment:9 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13600: surprising error message with bang pattern -------------------------------------+------------------------------------- Reporter: andrewufrank | Owner: v0d1ch Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.0.2 Resolution: | Keywords: BangPatterns, | newcomer Operating System: Unknown/Multiple | Architecture: Type of failure: Poor/confusing | Unknown/Multiple error message | Test Case: Blocked By: | Blocking: Related Tickets: #15166, #15458 | Differential Rev(s): Phab:D5040 Wiki Page: | -------------------------------------+------------------------------------- Changes (by v0d1ch): * differential: => Phab:D5040 -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13600#comment:10 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13600: surprising error message with bang pattern -------------------------------------+------------------------------------- Reporter: andrewufrank | Owner: v0d1ch Type: bug | Status: patch Priority: normal | Milestone: Component: Compiler | Version: 8.0.2 Resolution: | Keywords: BangPatterns, | newcomer Operating System: Unknown/Multiple | Architecture: Type of failure: Poor/confusing | Unknown/Multiple error message | Test Case: Blocked By: | Blocking: Related Tickets: #15166, #15458 | Differential Rev(s): Phab:D5040 Wiki Page: | -------------------------------------+------------------------------------- Changes (by v0d1ch): * status: new => patch -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13600#comment:11 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13600: surprising error message with bang pattern -------------------------------------+------------------------------------- Reporter: andrewufrank | Owner: v0d1ch Type: bug | Status: patch Priority: normal | Milestone: Component: Compiler | Version: 8.0.2 Resolution: | Keywords: BangPatterns, | newcomer Operating System: Unknown/Multiple | Architecture: Type of failure: Poor/confusing | Unknown/Multiple error message | Test Case: Blocked By: | Blocking: Related Tickets: #15166, #15458 | Differential Rev(s): Phab:D5040 Wiki Page: | -------------------------------------+------------------------------------- Comment (by sgraf): Just hit this with the following program missing `-XBangPatterns` from #11284: {{{ module T11284 where import Data.Char (isSpace) import Data.List (foldl') import GHC.Exts (build) import qualified Data.Text as T import qualified Data.Text.Array as A longestWord :: T.Text -> Int longestWord t = foldl' max 0 $ map T.length $ fusedWords t fusedWords :: T.Text -> [T.Text] fusedWords t0 = build $ \cons nil -> let go !t | T.null t = nil | otherwise = let (w, rest) = T.span (not . isSpace) t in cons w (go $ T.dropWhile isSpace rest) in go t0 -- For reference data Text = Text {-# UNPACK #-} !A.Array -- payload (Word16 elements) {-# UNPACK #-} !Int -- offset (units of Word16, not Char) {-# UNPACK #-} !Int -- length (units of Word16, not Char) }}} Complains with {{{ T11284.hs:18:6: error: Variable not in scope: go :: T.Text -> b | 18 | in go t0 }}} I'd say a warning when there's no space in a binary operator definition for `(!)` before its second parameter is the way to go. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13600#comment:12 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13600: surprising error message with bang pattern -------------------------------------+------------------------------------- Reporter: andrewufrank | Owner: v0d1ch Type: bug | Status: patch Priority: normal | Milestone: Component: Compiler | Version: 8.0.2 Resolution: | Keywords: BangPatterns, | newcomer Operating System: Unknown/Multiple | Architecture: Type of failure: Poor/confusing | Unknown/Multiple error message | Test Case: Blocked By: | Blocking: Related Tickets: #15166, #15458 | Differential Rev(s): Phab:D5040 Wiki Page: | -------------------------------------+------------------------------------- Comment (by v0d1ch): Thank you for the additional information! I am currently digging trough parser trying to find a place where this check should be added. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13600#comment:13 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13600: surprising error message with bang pattern -------------------------------------+------------------------------------- Reporter: andrewufrank | Owner: v0d1ch Type: bug | Status: patch Priority: normal | Milestone: Component: Compiler | Version: 8.0.2 Resolution: | Keywords: BangPatterns, | newcomer Operating System: Unknown/Multiple | Architecture: Type of failure: Poor/confusing | Unknown/Multiple error message | Test Case: Blocked By: | Blocking: Related Tickets: #15166, #15458 | Differential Rev(s): Phab:D5040 Wiki Page: | -------------------------------------+------------------------------------- Comment (by simonpj): It's not just a parsing thing. That definition of `go` really might be defining `(!)`, as if you'd written {{{ let (!) go t | T.null t = ... | otherwise = ... }}} We could simply discourage infix definitions of `(!)` (which is used for array indexing anyway), by issuing a warning and asking the user to write their definition prefix (as I have done above) to avoid the potential ambiguity with bang-patterns. Or, maybe only warn if there is no space between the `!` and the argument (comment:2). I dunno. This is user-facing, so a GHC proposal (a very small one!) might be indicated. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13600#comment:14 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13600: surprising error message with bang pattern -------------------------------------+------------------------------------- Reporter: andrewufrank | Owner: v0d1ch Type: bug | Status: patch Priority: normal | Milestone: Component: Compiler | Version: 8.0.2 Resolution: | Keywords: BangPatterns, | newcomer Operating System: Unknown/Multiple | Architecture: Type of failure: Poor/confusing | Unknown/Multiple error message | Test Case: Blocked By: | Blocking: Related Tickets: #15166, #15458 | Differential Rev(s): Phab:D5040 Wiki Page: | -------------------------------------+------------------------------------- Changes (by erikd): * cc: erikd (added) Comment: Seeing this with ghc 8.4.3 as well. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13600#comment:15 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13600: surprising error message with bang pattern -------------------------------------+------------------------------------- Reporter: andrewufrank | Owner: v0d1ch Type: bug | Status: patch Priority: normal | Milestone: Component: Compiler | Version: 8.0.2 Resolution: | Keywords: BangPatterns, | newcomer Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: Poor/confusing | Test Case: T13600, error message | T13600b Blocked By: | Blocking: Related Tickets: #15166, #15458 | Differential Rev(s): Phab:D5040 Wiki Page: | -------------------------------------+------------------------------------- Changes (by v0d1ch): * testcase: => T13600, T13600b -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13600#comment:16 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13600: surprising error message with bang pattern -------------------------------------+------------------------------------- Reporter: andrewufrank | Owner: v0d1ch Type: bug | Status: patch Priority: normal | Milestone: Component: Compiler | Version: 8.0.2 Resolution: | Keywords: BangPatterns, | newcomer Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: Poor/confusing | Test Case: T13600a, error message | T13600b Blocked By: | Blocking: Related Tickets: #15166, #15458 | Differential Rev(s): Phab:D5040 Wiki Page: | -------------------------------------+------------------------------------- Changes (by v0d1ch): * testcase: T13600, T13600b => T13600a, T13600b -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13600#comment:17 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13600: surprising error message with bang pattern
-------------------------------------+-------------------------------------
Reporter: andrewufrank | Owner: v0d1ch
Type: bug | Status: patch
Priority: normal | Milestone:
Component: Compiler | Version: 8.0.2
Resolution: | Keywords: BangPatterns,
| newcomer
Operating System: Unknown/Multiple | Architecture:
| Unknown/Multiple
Type of failure: Poor/confusing | Test Case: T13600a,
error message | T13600b
Blocked By: | Blocking:
Related Tickets: #15166, #15458 | Differential Rev(s): Phab:D5040
Wiki Page: |
-------------------------------------+-------------------------------------
Comment (by Ben Gamari

#13600: surprising error message with bang pattern -------------------------------------+------------------------------------- Reporter: andrewufrank | Owner: v0d1ch Type: bug | Status: closed Priority: normal | Milestone: 8.8.1 Component: Compiler | Version: 8.0.2 Resolution: fixed | Keywords: BangPatterns, | newcomer Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: Poor/confusing | Test Case: T13600a, error message | T13600b Blocked By: | Blocking: Related Tickets: #15166, #15458 | Differential Rev(s): Phab:D5040 Wiki Page: | -------------------------------------+------------------------------------- Changes (by bgamari): * status: patch => closed * resolution: => fixed * milestone: => 8.8.1 Comment: Thanks for tackling this, v0d1ch! -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13600#comment:19 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13600: surprising error message with bang pattern -------------------------------------+------------------------------------- Reporter: andrewufrank | Owner: v0d1ch Type: bug | Status: closed Priority: normal | Milestone: 8.8.1 Component: Compiler | Version: 8.0.2 Resolution: fixed | Keywords: BangPatterns, | newcomer Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: Poor/confusing | Test Case: T13600a, error message | T13600b Blocked By: | Blocking: Related Tickets: #15166, #15458 | Differential Rev(s): Phab:D5040 Wiki Page: | -------------------------------------+------------------------------------- Comment (by simonpj): My apologies -- I should have looked at the Phab earlier. Would it be possible to add a Note to explain what is happening in the code, perhaps near `Passer.warnSpaceAfterBang`. I believe that the specification is this: -------- GHC warns if it sees * A infix definition of `(!)` * that lacks a space before the `!` operator That is, something like {{{ x !p = e }}} where `p` is a pattern. If `BangPatterns` are on, this example would be treated as a definition of the function `x` applied the to the bang-pattern `!p`. If there is a space after the bang, thus {{{ x ! p = e }}} then the definition is treated as a definition of `(!)` (without `BangPatterns`) or as `x (!p) = e` (with `BangPatterns`), with no warning in either case. ------------ Is that the correct specification? If so, it'd be good to explain this in the user manual, and in the Note in the code. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13600#comment:20 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler
participants (1)
-
GHC