packages feed

applicative-extras (empty) → 0.1

raw patch · 6 files changed

+109/−0 lines, 6 filesdep +basedep +haskell98dep +mtlsetup-changed

Dependencies added: base, haskell98, mtl

Files

+ Control/Applicative/Compose.hs view
@@ -0,0 +1,15 @@+{-# LANGUAGE TypeOperators #-}+module Control.Applicative.Compose where++import Control.Applicative++-- | Type-level composition+newtype (f :+: g) a = Compose { decompose :: (f (g a)) }++instance (Functor f, Functor g) => Functor (f :+: g) where+  fmap f (Compose x) = Compose $ (fmap . fmap) f x++{- The composition of any two Applicatives is an idiom -}+instance (Applicative f, Applicative g) => Applicative (f :+: g) where+   pure x = Compose$ (pure pure) <*> (pure x)+   Compose fs <*> Compose xs = Compose $ pure (<*>) <*> fs <*> xs
+ Control/Applicative/Error.hs view
@@ -0,0 +1,33 @@+{-# LANGUAGE PatternGuards #-}+module Control.Applicative.Error where++import Control.Applicative++-- |An error idiom.  Rather like the error monad, but collect all+-- |errors together +data Failing a = Success a | Failure [ErrorMsg]+ deriving Show+type ErrorMsg = String++instance Functor Failing where+  fmap f (Failure fs) = Failure fs+  fmap f (Success a) = Success (f a)++instance Applicative Failing where+   pure = Success+   Failure msgs <*> Failure msgs' = Failure (msgs ++ msgs')+   Success _ <*> Failure msgs' = Failure msgs'+   Failure msgs' <*> Success _ = Failure msgs'+   Success f <*> Success x = Success (f x)++-- | Tries to read a value+maybeRead :: Read a +          => String     -- | The value+          -> String     -- | The error message+          -> Failing a+maybeRead s msg | [(i, _)] <- readsPrec 0 s = Success i+                | otherwise = Failure [msg]++-- | Tries to read an Integer+asInteger :: String -> Failing Integer+asInteger s = maybeRead s (s ++ " is not a valid integer")
+ Control/Applicative/State.hs view
@@ -0,0 +1,14 @@+module Control.Applicative.State (module Control.Monad.State) where++import Control.Applicative+import Control.Monad.State++{- A state idiom. -}+-- the freedom in reordering the effectful part of the computation comes+-- in that we can pass the state first to f and then to v or first to v and +-- then to s.  With monads we must first pass the state to f because+-- of the type of >>=.++instance Applicative (State a) where+   pure  = return+   (<*>) = ap
+ LICENSE view
@@ -0,0 +1,30 @@+Copyright (c) 2008, Tupil++All rights reserved.++Redistribution and use in source and binary forms, with or without+modification, are permitted provided that the following conditions are met:++    * Redistributions of source code must retain the above copyright+      notice, this list of conditions and the following disclaimer.++    * Redistributions in binary form must reproduce the above+      copyright notice, this list of conditions and the following+      disclaimer in the documentation and/or other materials provided+      with the distribution.++    * Neither the name of Tupil nor the names of other+      contributors may be used to endorse or promote products derived+      from this software without specific prior written permission.++THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT+OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ applicative-extras.cabal view
@@ -0,0 +1,15 @@+Name:            applicative-extras+Version:         0.1+Synopsis:        Instances for Applicative+Description:     Some instances for Applicative and type-level composition.+Category:        Control+License:         BSD3+License-file:    LICENSE+Copyright:       (c) Tupil+Author:          Chris Eidhof <ce+hackage@tupil.com>+Maintainer:      Chris Eidhof <ce+hackage@tupil.com>+Exposed-Modules:   Control.Applicative.Compose+                 , Control.Applicative.Error+                 , Control.Applicative.State+Build-Type:      Simple+Build-Depends:   base, haskell98, mtl