[Haskell-cafe] why can't you surround (+) in backticks and have it be infix?

Greg Buchholz haskell at sleepingsquirrel.org
Mon Jan 8 11:06:48 EST 2007


tphyahoo wrote:
> 
> "Issues: In Haskell, any function or constructor can be enclosed in backticks
> and then used as an infix operator. "
> 
> from http://www-users.cs.york.ac.uk/~mfn/hacle/issues/node2.html
> 
> But this seems to be contradicted by...
> 
> from #haskell
> 
> -- 09:19 < tphyahoo> >  let func = (+) in 1 `func` 2
> -- 09:19 < lambdabot>  3
> -- 09:20 < tphyahoo> but ......
> -- 09:20 < tphyahoo> 1 `(+)` 2
> -- 09:20 < tphyahoo> > 1 `(+)` 2
> -- 09:20 < lambdabot>  Parse error
> 
> (+) is a function, is it not?
> 
> Where's the rub?

    The thing inside the backticks has to be a syntatic name, not an
expression.  The grammar from the Haskell Report 
( http://www.haskell.org/onlinereport/syntax-iso.html )...

varid   ->    (small {small | large | digit | ' })<reservedid> 
conid   ->    large {small | large | digit | ' }

varop   ->    varsym  | `varid `   (variable operator) 
qvarop  ->    qvarsym | `qvarid `  (qualified variable operator) 
conop   ->    consym  | `conid `   (constructor operator) 
qconop  ->    gconsym | `qconid `  (qualified constructor operator)

...I've also thought it would be nice to be able to say things like...

    (foo `liftM2 (,)` bar)


Greg Buchholz



More information about the Haskell-Cafe mailing list