[GHC] #13669: Identifier "Otherwise" in guarded equation can crash a program

#13669: Identifier "Otherwise" in guarded equation can crash a program -------------------------------------+------------------------------------- Reporter: vanto | Owner: (none) Type: feature | Status: new request | Priority: normal | Milestone: Component: Compiler | Version: 8.0.2 Keywords: | Operating System: Unknown/Multiple Architecture: | Type of failure: Other Unknown/Multiple | Test Case: | Blocked By: Blocking: | Related Tickets: Differential Rev(s): | Wiki Page: -------------------------------------+------------------------------------- In GHC.Base the identifier {{{otherwise}}} is defined as the value "True" and it helps to make guards more readable.\\ The identifier {{{otherwise}}} is not secure.\\ We can change his property easily and trick the compiler.\\ As written in GHC Base, {{{otherwise = True}}} is perfectible.\\ The problem here is to protect the "otherwise" identifier from uncontrolled access.\\ See the code below and the result of the compilation as well as the output.\\ {{{ import qualified Prelude as P otherwise :: P.Bool otherwise = P.False fun :: (P.Num a, P.Ord a) => a -> [P.Char] fun x | x P.< 0 = "down" | otherwise = "up" main :: P.IO () main = P.print (fun 7) c:\Sourcehs>ghc -Wall otherwise.hs [1 of 1] Compiling Main ( otherwise.hs, otherwise.o ) otherwise.hs:7:1: warning: [-Wincomplete-patterns] Pattern match(es) are non-exhaustive In an equation for `fun': Patterns not matched: _ otherwise.hs:11:17: warning: [-Wtype-defaults] * Defaulting the following constraints to type `P.Integer' (P.Num a0) arising from a use of `fun' at otherwise.hs:11:17-21 (P.Ord a0) arising from a use of `fun' at otherwise.hs:11:17-21 * In the first argument of `P.print', namely `(fun 7)' In the expression: P.print (fun 7) In an equation for `main': main = P.print (fun 7) Linking otherwise.exe ... c:\Sourcehs>otherwise otherwise: otherwise.hs:(7,1)-(8,27): Non-exhaustive patterns in function fun }}} I propose three solutions: 1- Delete {{{otherwise}}} from GHC.Base and use only TRUE.\\ 2- Add {{{otherwise}}} as a reserved word or keyword.\\ 3- Create protected objects in Haskell. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13669 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13669: Identifier "Otherwise" in guarded equation can crash a program -------------------------------------+------------------------------------- Reporter: vanto | Owner: (none) Type: feature request | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.0.2 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: Other | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by Iceland_jack): You can replace `otherwise` by `let` which is a keyword ;) (The same is true of `True`: `pattern True = P.False`) -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13669#comment:1 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13669: Identifier "Otherwise" in guarded equation can crash a program -------------------------------------+------------------------------------- Reporter: vanto | Owner: (none) Type: feature request | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.0.2 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: Other | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by bgamari): You could replace `otherwise` in the ticket description with any other identifier provided by `Prelude` and the same argument will apply. However, I really don't think this is an argument for adding complexity to the language. In the case that `Prelude` is imported unqualified the user will be faced with an ambiguity error and there will be no confusion. If they really do import `Prelude` qualified and define or otherwise import another `otherwise`, then who are we to say they shouldn't? I've never heard of anyone complain of being confused by `otherwise`, or any other `Prelude`-defined identifier, not behaving as expected for this reason. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13669#comment:2 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13669: Identifier "Otherwise" in guarded equation can crash a program -------------------------------------+------------------------------------- Reporter: vanto | Owner: (none) Type: feature request | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.0.2 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: Other | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by goldfire): I'm with @bgamari here -- I see nothing unsettling about the original program. Note that GHC correctly identifies the pattern-match as non- exhaustive. Regardless of our opinions, writing up a [https://github.com/ghc-proposals /ghc-proposals proposal] is the official way to suggestions changes to the language GHC compiles. You may wish to do so. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13669#comment:3 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13669: Identifier "Otherwise" in guarded equation can crash a program -------------------------------------+------------------------------------- Reporter: vanto | Owner: (none) Type: feature request | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.0.2 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: Other | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by vanto): Reply to bgamari:\\
I've never heard of anyone complain of being confused by otherwise, or any other Prelude-defined identifier, not behaving as expected for this reason.\\ It's because you've never worried about the problem! There is a beginning for everything.
Golfire said:\\
writing up a proposal is the official way to suggestions changes to the language GHC compiles.\\ Ben, tells goldfire my problem with the proposals, please.\\
Reply to golfire:\\
Regardless of our opinions\\ Why do you hide your opinion in this ticket?
Reply to bgamari and goldfire:\\ I know you will not do anything. You follow your way and you do not ask yourself the right questions. Haskell is still a language for research. Do not neglect what others have done in the past with other languages even if they are not functional language.\\ -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13669#comment:4 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13669: Identifier "Otherwise" in guarded equation can crash a program -------------------------------------+------------------------------------- Reporter: vanto | Owner: (none) Type: feature request | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.0.2 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: Other | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by goldfire): I'm certainly agreed that there is a beginning for everything and that users can and should bring up new ideas with an effort to evolve the language. GHC is an open-source compiler for an open language. Anyone can write proposals for language changes and submit patches for inclusion in the compiler. The proposals process, as decided on by the community, is the way to get a consensus of opinion so that a change to the language can be made. This is why I said "Regardless of our opinions": our personal opinions don't really matter, because you can always make a proposal and seek community consensus beyond just the two of us. I'm not sure what problem you have had with the proposals process, but I don't think it's Ben's responsibility to explain. If you've already posted where your problem lies, please provide a link. While I'm not involved in the communities of other languages, I do use several non-functional languages. This past year, I taught courses in Java and C (as well as Haskell), and next year I will be teaching just Java in my courses. When I teach a programming languages course, the focus of the course will be Java, not Haskell. (This is because, with Java 8, Java supports programming in a large variety of modes, including functional.) So I don't think it's fair to presume our familiarity or lack thereof with other languages and the ideas stemming from these languages. Do you have a language in mind with the feature you are seeking here? But don't answer me here -- put it in the proposal! -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13669#comment:5 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13669: Identifier "Otherwise" in guarded equation can crash a program -------------------------------------+------------------------------------- Reporter: vanto | Owner: (none) Type: feature request | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.0.2 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: Other | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by vanto): Reply to goldfire:\\ Thank you for your opinion. I respect your choice.\\ I failed to explain why I do not write proposals.\\ Take a look at ticket {{{#13505}}}. Thank you for giving a reply in this ticket. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13669#comment:6 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13669: Identifier "Otherwise" in guarded equation can crash a program -------------------------------------+------------------------------------- Reporter: vanto | Owner: (none) Type: feature request | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.0.2 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: Other | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by vanto): Solution n° 2 appears to be well.\\ Note that {{{otherwise}}}, which is a guard, is reserved word in Miranda. Why not in Haskell? -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13669#comment:7 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13669: Identifier "Otherwise" in guarded equation can crash a program -------------------------------------+------------------------------------- Reporter: vanto | Owner: (none) Type: feature request | Status: closed Priority: normal | Milestone: Component: Compiler | Version: 8.0.2 Resolution: invalid | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: Other | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by vanto): * status: new => closed * resolution: => invalid Comment: This ticket is similar to ticket {{{#13757}}}. That's why I close it -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13669#comment:8 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler
participants (1)
-
GHC