[Haskell] Question about Infix/Postfix Operators in Haskell

Pedro Vasconcelos pv at dcs.st-and.ac.uk
Mon Oct 18 05:18:56 EDT 2004


On Mon, 18 Oct 2004 09:51:52 +0200
"Georg Martius" <mai99dgf at studserv.uni-leipzig.de> wrote:

> Hi,
> 
> On Mon, 18 Oct 2004 09:43:26 +0200, Peter Theissen <peter at tsunamis.de> wrote:
> 
> > Hi,
> > is there any possibility of defining Infix-/Postfixoperators
> > in Haskell?
> >
> > Example:
> > Plus :: Int, Int -> Int
> 
> Plus :: Int -> Int -> Int
> 
> > Plus x y = x + y
> >
> > an now I´m want to use Plus in another function as an infix:
> >
> > Times2:: x = x Plus x
> 
> Times2:: x = x `Plus` x

Another possiblity: define a new operator (let's call it $+) and you do
without the backquotes:


infixl 5 $+

($+) :: Int->Int->Int
x $+ y = x+y

times2 x = x $+ x

This way you can specify the associativy and binding precedence and
reduce the need for parenthesis.

Best regards,

Pedro

-- 
Pedro Vasconcelos, School of Computer Science, University of St Andrews
-----------------------------------------------------------------------
"The difference between Theory and Practice 
is greater in Practice than in Theory."


More information about the Haskell mailing list