Newbie proposal: operator backquoting
Hello, dear list members! I'm just a Haskell newbie, but I want to make some proposal to Haskell'. There are some tickets in tracking system, that inspired by conflict between binary operators and other use of the same lexeme. At least I found 3 of that: "get rid of unary '-' operator" (http://hackage.haskell.org/trac/haskell-prime/ticket/50), "Eliminate . as an operator" (http://hackage.haskell.org/trac/haskell-prime/ticket/20) and "Replace the array indexing operator, '!'" (http://hackage.haskell.org/trac/haskell-prime/ticket/96). IMHO, all specified problems may be made less embarrassing - if not completly solved - if Haskell' have some way to solve lexical ambiguity in concrete position. As for those problems have similar lexical construct (binary operator) on one side - and different construct on other side: so this solution must take place over binary operators. I propose to use the same construct, that always used to convert function application to binary operator: backquoting. Any lexeme, bounded by backquotes, will be treated by grammar as binary operator; and no special grammatic case can be applied. So: ('-'1) is operator section, \x -> x-1, while (-1) is negative number ('-'y) is operator section, \x -> x-y, while (-y) is unary function application, negate y foo '-'1 has two arguments, (-) and 1, while foo -1 has one argument, -1 F'.'g is composition of function and constructor, while F.g is qualified function name ('!'x) is operator section, while !x is bang pattern (or strictness annotation). I think, this proposal does not require neither big changes in Haskell grammar, nor it ruins any existing code. Alexander Dakhov.
I'm too sorry about that, but my post client does not compatible with Haskell: it replace all occurence of backquotes by ordinary quotes. Please, replace them back when look at my letter :(( Alexander Dakhov.
Hello, dear list members! I'm just a Haskell newbie, but I want to make some proposal to Haskell'. There are some tickets in tracking system, that inspired by conflict between binary operators and other use of the same lexeme. At least I found 3 of that: "get rid of unary '-' operator" (http://hackage.haskell.org/trac/haskell-prime/ticket/50), "Eliminate . as an operator" (http://hackage.haskell.org/trac/haskell-prime/ticket/20) and "Replace the array indexing operator, '!'" (http://hackage.haskell.org/trac/haskell-prime/ticket/96). IMHO, all specified problems may be made less embarrassing - if not completly solved - if Haskell' have some way to solve lexical ambiguity in concrete position. As for those problems have similar lexical construct (binary operator) on one side - and different construct on other side: so this solution must take place over binary operators. I propose to use the same construct, that always used to convert function application to binary operator: backquoting. Any lexeme, bounded by backquotes, will be treated by grammar as binary operator; and no special grammatic case can be applied. So: ('-'1) is operator section, \x -> x-1, while (-1) is negative number ('-'y) is operator section, \x -> x-y, while (-y) is unary function application, negate y foo '-'1 has two arguments, (-) and 1, while foo -1 has one argument, -1 F'.'g is composition of function and constructor, while F.g is qualified function name ('!'x) is operator section, while !x is bang pattern (or strictness annotation). I think, this proposal does not require neither big changes in Haskell grammar, nor it ruins any existing code.
Alexander Dakhov. _______________________________________________ Haskell-prime mailing list Haskell-prime@haskell.org http://www.haskell.org/mailman/listinfo/haskell-prime
On Thu, Jun 21, 2007 at 09:14:55AM +0400, Dusty wrote:
foo '-'1 has two arguments, (-) and 1, while foo -1 has one argument, -1
You mean foo '-'1 is parsed as (-) foo 1 and foo -1 is parsed as foo (-1) right? What would foo - 1 mean? If it means (-) foo 1 then putting the extra space in looks a lot nicer to me than using backquotes. If it means foo (-1) then I think this will break a lot of code, and is also very unintuitive. Thanks Ian, a member of the "Out with DMR, defaulting, unary negation and n+k patterns" club
On Mon, Jun 25, 2007 at 03:46:19PM +0100, Ian Lynagh wrote:
On Thu, Jun 21, 2007 at 09:14:55AM +0400, Dusty wrote:
foo '-'1 has two arguments, (-) and 1, while foo -1 has one argument, -1
As *I* understood this, foo - 1 would not change. In fact except for the new `varsym` and `consym` forms, the grammer would not change. How would this break existing code?
Thanks Ian, a member of the "Out with DMR, defaulting, unary negation and n+k patterns" club
Ian: what's DMR? Stefan
Stefan O'Rear writes:
what's DMR?
The something monomorphism restriction, is my guess. http://haskell.org/onlinereport/decls.html#sect4.5.5 -- -David House, dmhouse@gmail.com
Dusty writes:
I propose to use the same construct, that always used to convert function application to binary operator: backquoting. Any lexeme, bounded by backquotes, will be treated by grammar as binary operator; and no special grammatic case can be applied.
Presumably it wouldn't be _required_ to backquote operators. So the only time you'd be thinking of using backquotes is when you have some expression which is parsing weirdly, and you want to make it clearer. But then rather than using backquotes, as you propose, you could just disambiguate it in a different way that already exiss. For example, suppose you make the classic mistake of trying to use (.) with a constructor without putting sufficient space in: foo = Just.negate And this parses as the identifier 'negate' from the module Just. So under your proposal you could write this as: foo = Just`.`negate But equally one could just put spaces in: foo = Just . negate This is always possible. Therefore I don't see the value of your proposal, unless people get into the habit of using backquotes all the time, and thereby avoiding things like Just.negate from ever coming up in the first place. But I think this is unlikely. -- -David House, dmhouse@gmail.com
participants (5)
-
David House -
Dusty -
Ian Lynagh -
Neil Mitchell -
Stefan O'Rear