8

The other day I came across an operator, -<, appearing in the context of binding a value to a variable in a monad; specifically, it looks like this passes a value to a function which is then assigned (and possibly evaluated?) to a variable existing in the scope of a monad.

Example usage:

myMonad = do
    myVar <- f -< x

A few questions about this: first off, what's it called? The operator itself is un-googleable (Google doesn't like < or >), and the one name I've found, "arrow application", usually links to the other kind of Arrow present in Haskell, which seems unrelated.

Second, why is this operator not explained in most of the learning resources out there? Neither the "Gentle Introduction to Monads" nor LYAH give it so much as a passing mention, and most lists of Haskell operators forego it as well. (Is it considered bad practice?)

Finally, is this equivalent to using parentheses, as in, (myVar <- f -< x) == (myVar <- (f x))? Or is it more like using let myVar = (f x)? In either case, if this is how it's used, why use -< over parens or $?

1
  • 1
    when searching for symbols, hoogle and hayoo are your friends.
    – rampion
    May 16, 2015 at 16:42

1 Answer 1

16

Yes, that is the same kind of arrow. There is sugar syntax for arrows just like there is sugar syntax for monads. You can't use Google to search for -<, but you can use Hoogle.

See: GHC Language Features, Arrow tutorial.

Arrow syntax is indeed poorly documented. The reason that you can't use $ instead of -< is that -< injects a pure value into the arrow, but -> is only one example of an arrow. So, $ works fine if your arrow is ->. There are also monadic arrows (the Kleisli constructor creates those) and you can make your own arrows, and in these cases -< is different.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.