[Haskell-beginners] infix and bind pseudonym

Daniel Fischer daniel.is.fischer at web.de
Wed Mar 4 08:00:21 EST 2009


Am Mittwoch, 4. März 2009 13:25 schrieb Michael Easter:
> Folks,
>
> I have a simple type called Beverage and an example that allows me to
> construct Maybe Beverage types.
>
> Here are some type signatures for example functions:
>
> request :: String -> Maybe Beverage
>
> addMalt :: Beverage -> Maybe Beverage
>
> I have defined a chain function like so:
>
> chain :: (Maybe a) -> (a -> Maybe b) -> (Maybe b)
> chain = (>>=)
>
> I can do this:
>
> (chain (request "beer") addMalt)
>
> and
>
> request "beer" `chain` addMalt
>
> I think I understand why, as I use the back-ticks for infix.
>
> However, I don't have to do that for the true bind function, (>>=)
>
> request "beer" >>= addMalt
>
> I would like to use chain in this way -- that is without back-ticks.  I'm
> not sure how...

You can't.
Haskell has (infix) operators, whose names are composed of symbols (>, <, |, 
:, +, ...) and (prefix) functions, whose names are composed of letters, 
underscores (_) and primes (').
If you want to use a function infix or an operator prefix, you must indicate 
that to the compiler, which is done by enclosing a function name in backticks 
or an operator symbol in parentheses.

If you could use a function name infix or prefix without indicating which you 
want, what would

id const even

be? Should it be id `const` even or (id const) even?

>
> Is there something I'm missing?
>
> thanks
> Mike
>
> ps. Thanks to everyone for the great discussion on IO (re: previous
> question)



More information about the Beginners mailing list