[GHC] #15720: Assign to literals is allowed in ghci

#15720: Assign to literals is allowed in ghci -------------------------------------+------------------------------------- Reporter: sighingnow | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: GHCi | Version: 8.6.1 Keywords: | Operating System: Unknown/Multiple Architecture: | Type of failure: GHC accepts Unknown/Multiple | invalid program Test Case: | Blocked By: Blocking: | Related Tickets: Differential Rev(s): | Wiki Page: -------------------------------------+------------------------------------- I have been asked that why `1 = 2` is allowed in ghci, which is quite confusing for beginners. {{{
1 = 2 1 1 }}}
-- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/15720 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#15720: Assign to literals is allowed in ghci -------------------------------------+------------------------------------- Reporter: sighingnow | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: GHCi | Version: 8.6.1 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: GHC accepts | Unknown/Multiple invalid program | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by goldfire): This should perhaps be an on-by-default warning, but it's valid Haskell code. `1 = 2` is a lazy pattern match. Because it's lazy but binds no variables, we never see an error reported. This is maybe silly, but it doesn't quite seem worth putting another rule in Haskell to avoid this possibility. That said, a pattern-match that binds no variables is warned by `-Wunused- pattern-binds`; maybe this should really be its own warning. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/15720#comment:1 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#15720: Assign to literals is allowed in ghci -------------------------------------+------------------------------------- Reporter: sighingnow | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: GHCi | Version: 8.6.1 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: GHC accepts | Unknown/Multiple invalid program | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by sighingnow): Should we enable `-Wunused-pattern-binds` by default ? -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/15720#comment:2 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#15720: Assign to literals is allowed in ghci -------------------------------------+------------------------------------- Reporter: sighingnow | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: GHCi | Version: 8.6.1 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: GHC accepts | Unknown/Multiple invalid program | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by RyanGlScott): Replying to [comment:2 sighingnow]:
Should we enable `-Wunused-pattern-binds` by default ?
It's enabled by `-Wall`: {{{ $ ghci -Wall GHCi, version 8.4.3: http://www.haskell.org/ghc/ :? for help Loaded GHCi configuration from /home/ryanglscott/.ghci λ> 1 = 2 <interactive>:1:1: warning: [-Wtype-defaults] • Defaulting the following constraints to type ‘Integer’ (Eq a0) arising from the literal ‘1’ at <interactive>:1:1 (Num a0) arising from the literal ‘1’ at <interactive>:1:1 • In the pattern: 1 In a pattern binding: 1 = 2 <interactive>:1:1: warning: [-Wunused-pattern-binds] This pattern-binding binds no variables: 1 = 2 }}} I'd be hesitant to enable `-Wunused-pattern-binds` by default without a clear community consensus for it (perhaps in the form of a GHC proposal). -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/15720#comment:3 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#15720: Assign to literals is allowed in ghci -------------------------------------+------------------------------------- Reporter: sighingnow | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: GHCi | Version: 8.6.1 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: GHC accepts | Unknown/Multiple invalid program | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by goldfire): I had thought that `-Wunused-pattern-binds` did more than just this corner case... looking at it now ([https://downloads.haskell.org/~ghc/latest/docs/html/users_guide/using- warnings.html#ghc-flag--Wunused-pattern-binds manual entry]), I do think we should enable this by default. I suppose a proposal is in order, but that's annoyingly heavy. Oh well. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/15720#comment:4 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler
participants (1)
-
GHC