
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!)