In Haskell, I often use >>=it >>to create monadic actions. For example:
> Just 1 >>= Just . (+1) >> Just ()
Just ()
There is only flatMap in Scala, so I decided to use Scalaz >>=and >>. The problem is that I have an error with the code:
> 1.some >>= { i:Int => (i+1).some } >> ().some
<console>:14: error: type mismatch;
found : Option[Unit]
required: Int => ?
1.some >>= { i:Int => (i+1).some } >> ().some
^
I was sure that the above expression was equal
1.some.>>=({ i:Int => (i+1).some }).>>(().some)
but it works as expected. I think scalac interprets the code as
1.some >>= ({ i:Int => (i+1).some } >> ().some)
which is obviously wrong due to type >>. Am I right to interpret? If so, what are the syntax rules? If I still want to use >>=, and >>in the same terms, the best solution is to wrap arg1 >>= arg2inside the brackets? How:
(1.some >>= { i:Int => (i+1).some }) >> ().some