What does>> = mean in purescript?

I read the purescript wiki and found the next section that explains doin terms >>=.

What does it mean >>=?

Mark

The do keyword introduces simple syntactic sugar for a monadic expression.

Here is an example using a monad for a type Maybe:

 maybeSum :: Maybe Number -> Maybe Number -> Maybe Number 
 maybeSum a b = do   
     n <- a
     m <- b   
     let result = n + m   
     return result 

maybeSumtakes two values ​​of the type Maybe Numberand returns their sum if none of them is Nothing.

When using notation, there must be an appropriate instance of a class of type Monad for the return type. Applications may take the following form:

  • a <- xwhich desugars on x >>= \a -> ...
  • xwhich desugars on x >>= \_ -> ...or just x if this is the last statement.
  • let a = x. in.

maybeSum desugars to::

 maybeSum a b =
   a >>= \n ->
     b >>= \m ->
       let result = n + m
       in return result
+4
1

>>= - , . Prelude (>>=) :: forall m a b. (Bind m) => m a -> (a -> m b) -> m b, bind bind. Prelude , .

Monad Haskell, . SO , , ( ).

+6

Source: https://habr.com/ru/post/1626951/


All Articles