packages feed

MicroHs-0.17.4.0 / lib / Control / Applicative.hs

module Control.Applicative(  Applicative(..),  (<$>), (<$), (<**>),  liftA, liftA3,  Alternative(..),  guard, asum, optional,  module Data.Functor.Const_Type,  ZipList(..),  WrappedMonad(..),  WrappedArrow(..),  ) whereimport qualified Prelude()              -- do not import Preludeimport Primitivesimport {-# SOURCE #-} Control.WrappedMonadimport Data.Bool_Typeimport Data.Coerceimport Data.Functorimport Data.Functionimport Data.List_Typeimport Data.Maybe_Typeimport Data.Ordimport Data.Functor.Const_Typeimport {-# SOURCE #-} Data.Typeableimport {-# SOURCE #-} Data.ZipList--import Mhs.Builtininfixl 4 <*>, *>, <*, <**>class Functor f => Applicative f where  pure        :: forall a . a -> f a  (<*>)       :: forall a b . f (a -> b) -> f a -> f b  (*>)        :: forall a b . f a -> f b -> f b  (<*)        :: forall a b . f a -> f b -> f a  liftA2      :: forall a b c . (a -> b -> c) -> f a -> f b -> f c  (<*>)        = liftA2 id  a1 *> a2     = (id <$ a1) <*> a2  a1 <* a2     = const <$> a1 <*> a2  liftA2 f a b = f <$> a <*> binstance Applicative ((->) a) where  pure = const  f <*> g = \ a -> f a (g a)instance Applicative Down where    pure = Down    (<*>) = coerceliftA :: forall f a b . Applicative f => (a -> b) -> f a -> f bliftA f a = f <$> aliftA3 :: forall f a b c d . Applicative f => (a -> b -> c -> d) -> f a -> f b -> f c -> f dliftA3 f a b c = f <$> a <*> b <*> c(<**>) :: forall f a b . Applicative f => f a -> f (a -> b) -> f b(<**>) = liftA2 (\ a f -> f a)-------------------------------------------------------infixl 3 <|>class Applicative f => Alternative f where    empty :: forall a . f a    (<|>) :: forall a . f a -> f a -> f a    some :: forall a . f a -> f [a]    some a = (:) <$> a <*> many a    many :: forall a . f a -> f [a]    many a = some a <|> pure []guard :: forall f a . Alternative f => Bool -> f ()guard b = if b then pure () else emptyasum :: forall f a . Alternative f => [f a] -> f aasum [] = emptyasum (a:as) = a <|> asum asoptional :: forall f a . Alternative f => f a -> f (Maybe a)optional a = Just <$> a <|> pure Nothing