applicative-logic 0.1.0.1 → 0.1.0.2
raw patch · 2 files changed
+28/−22 lines, 2 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
Files
- applicative-logic.cabal +3/−3
- src/Control/Applicative/Logic.hs +25/−19
applicative-logic.cabal view
@@ -1,11 +1,11 @@ cabal-version: 3.0 name: applicative-logic-version: 0.1.0.1+version: 0.1.0.2 synopsis: Generalized logic operations for Applicative and Alternative functors --- description:-homepage: http://hakon.gylterud.net/programming/applicative-logic+description: This library contains a generalisation of local functions such as "any" and "all" to Applicative and Alternative functors.+homepage: http://hakon.gylterud.net/programming/applicative-logic.html license: BSD-3-Clause license-file: LICENSE author: Håkon Robbestad Gylterud
src/Control/Applicative/Logic.hs view
@@ -1,3 +1,14 @@+{-|+Module : Control.Applicative.Logic+Description : Generalized logic operations for Applicative and Alternative functors+Copyright : (c) Håkon Robbestad Gylterud, Year+License : BSD-3-Clause+Maintainer : lyesveasp@openbastille.org+Stability : experimental+Portability : POSIX++This library contains a generalisation of local functions such as "any" and "all" to Applicative and Alternative functors.+-} module Control.Applicative.Logic (any,or,all,and,(&&),convert,Searchable,search) where import Control.Applicative@@ -12,8 +23,7 @@ -- | Generalized version of 'Prelude.any'. It takes a predicate that returns -- generalised truth values in an 'Alternative' functor and applies it disjunctively to -- a foldable structure. I.e. it applies the predicate and folds with <|>.--- any :: (Alternative f, Foldable t) => (a -> f b) -> t a -> f b--- @+ any :: (Alternative f, Foldable t) => (a -> f b) -> t a -> f b any = ($ false) . foldr . ((<|>) .) @@ -21,11 +31,7 @@ -- truth values in an Applicative functor on a Monoid and applies it conjunctively to -- a foldable structure. I.e. it applies the predicate and folds with an applicative -- lifting of monoidal concatenation ('<>').--- --- @--- all :: (Applicative f, Monoid b, Foldable t) => (a -> f b) -> t a -> f b--- @---+ all :: (Applicative f, Monoid b, Foldable t) => (a -> f b) -> t a -> f b all = ($ true) . foldr . (liftA2 (<>) <$>)@@ -33,23 +39,21 @@ -- | Generalized version of the boolean 'or' to foldable structures of 'Alternative' functorial values. -- It combines the elements using the alternative choice operator ('<|>').------ @--- or :: (Alternative f, Foldable t) => t (f a) -> f a--- @+ or :: (Alternative f, Foldable t) => t (f a) -> f a or = any id --- | Generalized version of the boolean 'and' to foldable structures of 'Applicative' functor applied to monoids. It combines the elements using the monoidal concatenation ('<>').------ @--- and :: (Applicative f, Monoid a, Foldable t) => t (f a) -> f a--- @+-- | Generalized version of the boolean 'and' to foldable structures of+-- 'Applicative' functor applied to monoids. It combines the elements using the+-- monoidal concatenation ('<>').+ and :: (Applicative f, Monoid a, Foldable t) => t (f a) -> f a and = all id +-- | Generalized version of the boolean '&&' operator for 'Applicative' functors applied to monoids.+-- It sequences and combines two applicative values using the monoidal operation ('<>'). (&&) :: (Applicative f, Monoid a) => f a -> f a -> f a (&&) = liftA2 (<>)@@ -57,16 +61,18 @@ -- | Converts a foldable structure into an 'Alternative' functor, where each element is lifted into the -- functor using 'pure' and then combined using the alternative choice operator ('<|>'). ----- @--- convert :: (Alternative f, Foldable t) => t a -> f a--- @ convert :: (Alternative f, Foldable t) => t a -> f a convert = any pure +-- | 'Searchable' class represents structures that can be searched using a predicate.+-- An instance may use 'all' or 'any' to iterate over parts of its structure depending+-- on wether the substrcutres are conjunctive or disjunctive. class (Foldable t) => Searchable t where+ -- | Search a structure using a predicate search :: (Alternative f, Monoid b) => (a -> f b) -> t a -> f b +-- | 'Maybe' instance of 'Searchable'. instance Searchable Maybe where search = any