Semigroupoids.Do

semigroupoids-5.3.7: Semigroupoids: Category sans id

Safe Haskell | Safe
Language | Haskell2010

Semigroupoids.Do

Description

This module re-exports operators from Data.Functor.Apply and Data.Functor.Bind, but under the same names as their `Applicative` and `Monad` counterparts. This makes it convenient to use do-notation on a type that is a `Bind` but not a monad (or an `Apply` but not an `Applicative` with `ApplicativeDo`), either using the `QualifiedDo` extension or the more traditional `RebindableSyntax`.

    {-# LANGUAGE ApplicativeDo #-}
    {-# LANGUAGE QualifiedDo #-}

    foo :: Apply f => f a -> f b -> f (a, b)
    foo as bs = Semi.do
      a <- as
      b <- bs
      pure (a, b)

    bar :: Bind m => (a -> b -> m c) -> m a -> m b -> m c
    bar f as bs = Semi.do
      a <- as
      b <- bs
      f a b

Synopsis

- fmap :: Functor f => (a -> b) -> f a -> f b
- (<*) :: Apply f => f a -> f b -> f a
- (*>) :: Apply f => f a -> f b -> f b
- (<*>) :: Apply f => f (a -> b) -> f a -> f b
- (>>) :: Bind m => m a -> m b -> m b
- (>>=) :: Bind m => m a -> (a -> m b) -> m b
- join :: Bind m => m (m a) -> m a
- pure :: Applicative f => a -> f a
- return :: Monad m => a -> m a
- fail :: Plus m => String -> m a

# Documentation

fmap :: Functor f => (a -> b) -> f a -> f b #

(<*) :: Apply f => f a -> f b -> f a #

Since: 5.3.6

(*>) :: Apply f => f a -> f b -> f b #

Since: 5.3.6

(<*>) :: Apply f => f (a -> b) -> f a -> f b #

Since: 5.3.6

(>>) :: Bind m => m a -> m b -> m b #

Since: 5.3.6

(>>=) :: Bind m => m a -> (a -> m b) -> m b #

Since: 5.3.6

join :: Bind m => m (m a) -> m a #

pure :: Applicative f => a -> f a #

return :: Monad m => a -> m a #

fail :: Plus m => String -> m a #

# Important note

This ignores whatever `String` you give it. It is a bad idea to use `fail` as a form of labelled error; instead, it should only be defaulted to when a pattern match fails.

Since: 5.3.6