[GHC] #13602: Pattern syntax in expression context must be clarified

#13602: Pattern syntax in expression context must be clarified -------------------------------------+------------------------------------- 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: Incorrect Unknown/Multiple | error/warning at compile-time Test Case: | Blocked By: Blocking: | Related Tickets: Differential Rev(s): | Wiki Page: -------------------------------------+------------------------------------- To simonpj\\ see tickets {{{#13557}}} and {{{#13579}}}\\ Typed Holes does not exist if we compile with GHC version 7.6.3. Instead of "error found holes" it indicates "pattern syntax in expression context: _".\\ I then understood that to improve Typed Holes it was first necessary to remove the ambiguity of the error in GHC 7.6.3 about pattern syntax in expression.\\ {{{let f = [True | x <- [_, _]]}}} raise the error {{{pattern syntax in expression context: _}}}\\ But as Typed Holes, this error has no sense here.\\ {{{let f' = [_ | x <- [1,2]]}}}will give a result like {{{"__"}}} And this calculation also makes sense if one refers to the rule of inference, as the function {{{f}}} .\\ \\ The compiler should not impose its way.\\ The programmer must be the master of his code. Here the rule of inference seems flouted.\\ Good sense or reason is argued to be the same in all people, yet differences in opinion are not due to differences in intelligence but to the fact that we use different approaches and consider different things.\\ Here you will find some ideas:\\ Instead of "underscore _" as "pattern syntax" we could use a new type called "indefinite" in expression.\\ Any calculation with "indefinite" will result in "indefinite".\\ In another calculation, the "indefinite" type could have a type defined according to a directive applied to the compiler.\\ example:\\ indefinite :: Int\\ f = [1,2,3,indefinite,5,6]\\ I took a look at ticket {{{#9497}}} and find it very interesting.\\ -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13602 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13602: Pattern syntax in expression context must be clarified -------------------------------------+------------------------------------- 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: Type of failure: Incorrect | Unknown/Multiple error/warning at compile-time | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by bgamari): Replying to [ticket:13602 vanto]:
{{{let f = [True | x <- [_, _]]}}} raise the error {{{pattern syntax in expression context: _}}}\\ But as Typed Holes, this error has no sense here.\\
{{{let f' = [_ | x <- [1,2]]}}}will give a result like {{{"__"}}} And this calculation also makes sense if one refers to the
rule of inference, as the function
{{{f}}} .\\
I'm afraid I still don't follow. What, specifically, is the issue you want solved? It seems to have something to do with holes, but I can't discern what from your text. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13602#comment:1 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13602: Pattern syntax in expression context must be clarified -------------------------------------+------------------------------------- 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: Type of failure: Incorrect | Unknown/Multiple error/warning at compile-time | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by goldfire): I think to move this forward, we need 3 things: 1. A concrete example (chunk of Haskell code) 2. What GHC does with this code today 3. What you would like GHC to do with this code Sometimes, several examples (each with points 1, 2, and 3) are helpful. ''Separately'' (either above or below), explain your motivation. It can be hard sometimes when the motivation and concrete examples are mixed together. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13602#comment:2 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13602: Pattern syntax in expression context must be clarified -------------------------------------+------------------------------------- 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: Type of failure: Incorrect | Unknown/Multiple error/warning at compile-time | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by vanto): Hello goldfire,\\ Well! it's OK.\\ But before, could you tell me which list of these two lists that makes good sense to you?\\ {{{f1 = [-4, -4, -3, -2, 0, 3, 8]}}}\\ {{{f2 = [-4, -4, -3, -2, 1, 3, 8]}}}\\ And tell me why? Maybe it just seems "logical" for you?\\ Explain your motivation :\\ The focus here is on an incomprehensible result (that makes no sense) of list comprehension in certain situations which I shall try to explain here.\\ Before I begin, I ask you to forget everything you've learned about the Haskell language. Erase everything from your memory and keep only the syntax of the language.\\ 1. What is a list comprehension\\ It allow many functions on lists to be defined in simple manner. It employs a syntax adapted from conventional mathematics for describing sets. The syntax is: {{{[exp | qual1 , ... , qualn]}}}\\ in which exp denotes an arbitrary expression, and a qualifier is either a boolean-valued expression or a generator. The forms for a generator we shall use is: {{{variable <- [list]}}}\\ The best way of explaining what list comprehensions do is to give some examples.\\ {{{
[x * x | x <- [1..10], even x] [4,16,36,64,100] }}}
This list comprehension reads: the list of values x * x, where x is drawn from the list [1..10] and x is even.\\ {{{
[3 | j <- [1..4]] [3,3,3,3] [ x | x <- [1..3], y <- ['a','b']] [1,1,2,2,3,3] [(\x -> True) j | j <- [(\x -> x), (\y -> y+1)]] [True, True] [(\x -> True) j | j <- ['"', '"']] [True, True] [(\x -> True) j | j <- ['`', '`']] [True, True] [(\x -> True) j | j <- [_ , _]] [True, True] }}}
2. A concrete example (chunk of Haskell code)\\ see above.\\ All this codes are correct codes and the compiler works fine.\\ 3. What GHC was doing with this code before today.\\ For some reason someone raised an exception when an "underscore" was in an expression (inside a generator of a list expression, as far as we are concerned here)\\ This is how the following code generates an error in GHC 7.6.3\\ {{{> [(\x -> True) j | j <- [_ , _]]}}} pattern syntax in expression context: _\\ And it does not make good sense.\\ Do you "see" that "it makes no sense"?\\ Imagine that someone removes the numeric value of the expression.\\ {{{
[(\x -> True) j | j <- [1, 2]] }}} The compiler will report an error like "found numeric value in expression". This also makes no sense.\\ Do you "see" that?\\
Reverse the problem. May be that the error is justified. Then the underscore is badly used in the syntax and must be rewritten, I think.\\ 4. What GHC does with this code today.\\ Today, the error "pattern syntax..." no longer exists. Someone created Typed Holes. And now the error is "Found Typed Holes..." And this also makes no sense in the example above.\\ Reverse the problem, and rewrite the underscore syntax if justified.\\ 5. What you would like GHC to do with this code.\\ I do not know if at this point you understood this " it makes a no sense".\\ Well, avoid the compiler to provide results who makes no sense of course!.\\ one more thing.\\ Take a look in the book "Ada 2012" from Dr. John Barnes and see page 24-25 about some behaviour of C language or in the book "Ada 2005" from the same author and see page 24-25 too. It's amazing. Although not speaking of the same thing, I think you will understand the connection between these things.\\ -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13602#comment:3 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13602: Pattern syntax in expression context must be clarified -------------------------------------+------------------------------------- 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: Type of failure: Incorrect | Unknown/Multiple error/warning at compile-time | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by vanto): * status: new => closed * resolution: => invalid Comment: See ticket {{{#13631}}} instead. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13602#comment:4 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler
participants (1)
-
GHC