Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

There's no actual magic syntax, just some ordinary operators.

    (<$>) is infix "fmap"
    (<*>) is infix "ap"
The "fmap" function lets you apply something of the form (a -> b) to a value of the form (m a), to get something of the form (m b). Specialized to lists, it's the familiar "map" function, but there are a lot of other things it can apply to.

The "ap" function lets you apply a "wrapped" function to a "wrapped" value - "apply this list of functions to that list of values".

The way these combine, along with currying, means you get a well known pattern for applying a many argument function to many wrapped values:

    <$> before the first argument
    <*> before every remaining argument
It works out like this:

    let add3 :: Integer -> Integer -> Integer -> Integer
        add3 x y z = x + y + z

    (add3 5) :: Integer -> Integer -> Integer
    (add3 <$> Just 5) :: Maybe (Integer -> Integer -> Integer)
    (add3 <$> Just 5 <*> Just 3) :: Maybe (Integer -> Integer)
    (add3 <$> Just 5 <*> Just 3 <*> Just 9) :: Maybe Integer


Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: