[Haskell-beginners] Re: map question

Will Ness will_n48 at yahoo.com
Sun Oct 18 18:32:31 EDT 2009


Deniz Dogan <deniz.a.m.dogan <at> gmail.com> writes:

> 2009/10/18 Will Ness <will_n48 <at> yahoo.com>:
> > 
> > exactly, just that it would be a _binary_ (-) .
> 
> So the only case where `(this)` syntax would be useful is where you
> want to make GHC understand you mean the binary (-) operator and you
> want to use point-free code. Now you have the choice between `(-)` and
> subtract, which one will it be? :)

  subtract = flip (-)  -- binary
  (`-`)    = (-)       -- binary

The only one place where I'd like to use it, is in (`-`2), instead of (flip (-) 
2) or (subtract 2) or (\a->a-2) or anything else.

Also, it is not `(-)` syntax that I'm advocating for, but `-` syntax, in 
sections, to guide the selection of the operator's _binary_ version over its 
_unary_ version. 

Actually, I suspect there is no unary (-), but rather in (-2) the "-" is a part 
of number read syntax. Having it enclosed in backticks would stop it being read 
as a part of a number, and thus ensure it being correctly interpreted as an 
operator, binary as any other Haskell operator:

  Prelude> :t (-)
  (-) :: (Num a) => a -> a -> a

  Prelude> :t (`-`2)
  <interactive>:1:2: parse error on input `-'

Even (`-`) may be left as invalid syntax, as it is today:

  Prelude> :t (`foldl`)
  <interactive>:1:8: parse error on input `)'

  Prelude> :t (`foldl`0)
  (`foldl`0) :: (Num a) => (a -> b -> a) -> [b] -> a





More information about the Beginners mailing list