Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

Haskell: Infix functions

Till now we called the functions like Function name followed by arguments. This kind of notation is called prefix notation, since function name comes before arguments. If a function takes more than one argument, then you can use it in both prefix and infix notation.

For example,
*Main> let sum x y = (x + y)
*Main> sum 10 20

How to use sum function in infix notation?
Argument1 `functionName` Argument2

*Main> 123 `sum` 1234
*Main> 123 `sum` 1234 `sum` 3456

Usually, you can apply a function in infix notation, when it is taking exactly two arguments. When a function takes more than 2 arguments, you need extra parenthesis.
*Main> let processData x y z = (x-z) * y
*Main> ((10) `processData` 20) 30
*Main> ((10) `processData` 20) 10

In Haskell the functions whose name consists of alphanumeric characters are prefix by default, and the functions made up from non alpha numeric character like +, >, $ etc are infix by default. For example, you can define an infix function like,

This post first appeared on Java Tutorial : Blog To Learn Java Programming, please read the originial post: here

Share the post

Haskell: Infix functions


Subscribe to Java Tutorial : Blog To Learn Java Programming

Get updates delivered right to your inbox!

Thank you for your subscription