Personal tools

Infix operator

From HaskellWiki

Revision as of 11:39, 18 July 2007 by Jimmy (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

1 Overview

Functions in Haskell are usually called using prefix notation, or the function name followed by its arguments. However, some functions, like +, are called with infix notation, or putting the function name between its two arguments.

2 Using infix functions with prefix notation

Putting parenthesis around an infix operator converts it into a prefix function:

 Prelude> (+) 1 2
 Prelude> (*) 3 4

3 Using prefix functions with infix notation

Putting ` marks around a prefix function allows us to use it like an infix function:

 Prelude> let concatPrint x y = putStrLn $ (++) x y
 Prelude> concatPrint "a" "b"
 Prelude> "a" `concatPrint` "b"

Note that you can only do this with a function that takes two arguments.