[Haskell-beginners] infix and bind pseudonym
Magnus Therning
magnus at therning.org
Wed Mar 4 07:59:58 EST 2009
On Wed, Mar 4, 2009 at 12:25 PM, Michael Easter <codetojoy at gmail.com> wrote:
>
> 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...
>
> Is there something I'm missing?
Yes, there are certain function names that allow infix usage without
the back-ticks, the name 'chain' doesn't. What those function names
are? Roughly you can say that functions that they are functions that
look like binary operations, like + - ++ >>> etc. I'm not sure I read
the pangauage spec correctly, but it looks like operators are made up
of the following characters !@#$%^&*+-./\|<=>?~ (IIRC ':' has a
special meaning in that it's allowed in "constructors", cf 1:2:[]).
/M
--
Magnus Therning (OpenPGP: 0xAB4DFBA4)
magnus@therning.org Jabber: magnus@therning.org
http://therning.org/magnus identi.ca|twitter: magthe
More information about the Beginners
mailing list