
Hello, In Haskell, backquotes can be used to convert individual identifiers into infix operators, but not complex expressions. For example, [1,2,3] `zip` [4,5,6] is OK, but not [1,2,3] `zipWith (+)` [4,5,6] Is there any reason other than potential confusion when one of the two backquotes is accidentally omitted? In any case, perhaps some people on this mailing list would appreciate the following implementation of "infix expressions" that Dylan Thurston and I came up with -- as algebraic and perverse as we could manage: infixr 0 -:, :- data Infix f y = f :- y x -:f:- y = x `f` y main = print $ [1,2,3] -: zipWith (+) :- [4,5,6] -- Edit this signature at http://www.digitas.harvard.edu/cgi-bin/ken/sig The trick is that there is no trick.

Is there any reason other than potential confusion when one of the two backquotes is accidentally omitted?
I thought about this a while ago and I think it probably simply has to do with complexity of expressions. If you allow arbitrary expressions to appear within the ticks, you have a problem with: x `f a `b` g c` y does this mean (b (f a) (g c)) x y or f a x (g c b y) or what? You could impose the constraint that you can't have embedded ticks, but this would grossify the CFG. Furthermore, you then have the case of, why isn't this valid: a `f (x `g` y)` b where the embedding is unambiguous because of the parentheses. i don't really know, but i find this fairly difficult to read. a `h` b where h = x `g` y is a lot simpler imo... - Hal

Ken Shan
In Haskell, backquotes can be used to convert individual identifiers into infix operators, but not complex expressions. For example,
[1,2,3] `zip` [4,5,6]
is OK, but not
[1,2,3] `zipWith (+)` [4,5,6]
Is there any reason other than potential confusion when one of the two backquotes is accidentally omitted?
I've often wondered about this myself, but it's difficult to make a pleasant distinction between what's allowed in between `` and an ordinary expression. They can't be the same because you can't nest them. Using a matched pair of quotation marks would work, but then you have the possibility of writing really horrid expressions.
In any case, perhaps some people on this mailing list would appreciate the following implementation of "infix expressions" that Dylan Thurston and I came up with -- as algebraic and perverse as we could manage:
infixr 0 -:, :- data Infix f y = f :- y x -:f:- y = x `f` y
main = print $ [1,2,3] -: zipWith (+) :- [4,5,6]
Yes, I appreciate that! It reminds me of how I got the syntax of Ponder -- which had no predefined operators, not even "if" -- to work.
The trick is that there is no trick.
Oh, I think it /is/ a trick :-) Jón -- Jón Fairbairn Jon.Fairbairn@cl.cam.ac.uk 31 Chalmers Road jf@cl.cam.ac.uk Cambridge CB1 3SZ +44 1223 570179 (after 14:00 only, please!)
participants (3)
-
Hal Daume III
-
Jon Fairbairn
-
Ken Shan