Infix operator with missing argument

438 views Asked by At

Is it possible with Haskell to have an operator (infix function) working with a missing argument ? (rather like - meaning a subtraction or a negative sign)

For example, I have this operator :

data1 <*> data2

Is it possible to make it work with a default value if first argument is omitted ?

<*> data2
1

There are 1 answers

0
Daniel Wagner On BEST ANSWER

Not really, no. On the other hand, you could perfectly well define a different operation that provides the default argument, e.g.

withDef data2 = {- your default value -} <*> data2

If you really want to use a name that would otherwise be an operator, you can still name this partially applied function with an operator name:

($<*>) data2 = {- default value -} <*> data2

It can be used prefix, as in ($<*>) data2, or postfix with appropriate GHC extensions, as in (data2 $<*>). The parentheses are not optional.