4 ms·
Interesting point with regards to functional programming, although it's worth pointing out that at least some functional languages have operators that allow you
by overgard 16y ago
Interesting point with regards to functional programming, although it's worth pointing out that at least some functional languages have operators that allow you to do what you're describing. For instance, in F# instead of writing "f x" you can write "x |> f"
- ionfish 16y agoFor functions of one argument that's easily enough defined in Haskell. x |> f = f x
- overgard 16y agoI don't know Haskell very well, but I assume you're defining an |> function? If so that's pretty neat. Haskell's flexibility always impresses me. I think the F# version generally assumes one argument too, though I think you could use partial function application to work with multiple parameters.
- ionfish 16y agoYes, that's right. Infix function names (anything made of symbols or delimited by backticks) are allowed on the LHS of a defining equation. An alternative syntax for this function would be this: (|>) f x = f x The parentheses just serve to denote an infix operator being used in a prefix way. A type signature makes this clearer: (|>) :: a -> (a -> b) -> b As you can see, (|>) is a function which accepts an argument of type a, a function which takes an argument of type a and returns something of type b, and returns something of type b. In this way it's just a flipped version of the application operator ($), which has this type: ($) :: (a -> b) -> a -> b
- T-R 16y agoI was just thinking about that. You have to do it by hacking the infix syntactic sugar. x |> f = f x gives you lambda calculus, but it gets ugly, since you need to specify order of operations with parentheses. (4 |> (5 |> (+))) |> (3 |> (*)) You can take it a step further with tuples, but you still need to be explicit about the number of arguments: (x,y) |> f = f x y ((4,5) |> (+), 3) |> (*) Maybe you could go almost all the way by telling it to create a List when passed two values, and telling it apply to the (nested) List when called with a List and an operator, but off hand, I can't think of a way to get it to type check, particularly not without killing currying.