Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

> That's not an operator, that's a lambda. The end result is the same, but semantically it's very different.

It's not, actually. In most functional languages — including F# — operators are just a special case of functions. Haskell will let you both use operators as (prefix) functions (via sections):

    Prelude> (/) 42 2
    21.0
or use functions as (infix, binary) operators:

    Prelude> even `filter` [0..20]
    [0,2,4,6,8,10,12,14,16,18,20]
and operators are defined exactly the same way you'd define functions:

    Prelude> let (><) a b = a * b in 3 >< 4
    12
although you can define them infix if you prefer:

    Prelude> let a >< b = a * b in 3 >< 4
    12
then again, you can also define functions using infix syntax:

    Prelude> let a `add` b = a + b in add 3 4
    7
You can also partially apply operators (again, via sections):

    Prelude> :t (1 +)
    (1 +) :: Num a => a -> a
in roughly the same way you'd partially apply functions:

    Prelude> :t map (+ 1)
    map (+ 1) :: Num b => [b] -> [b]
> Passing around an operator means you don't need to know the types involved

Uh? You need to know them in exactly the same way you do for functions.

> you can have a function that operates on any two values and applies an operator to them.

No, you most definitely can't, both operators and functions are typed. They work the exact same way but for the syntactic difference that operators are infix and may have precedence junk on top. But that's parsing, aside from that, a functional language will treat functions and operators the same way (outside of the odd builtin)



Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: