applicative-logic (empty) → 0.1.0.1
raw patch · 4 files changed
+136/−0 lines, 4 filesdep +base
Dependencies added: base
Files
- CHANGELOG.md +5/−0
- LICENSE +30/−0
- applicative-logic.cabal +28/−0
- src/Control/Applicative/Logic.hs +73/−0
+ CHANGELOG.md view
@@ -0,0 +1,5 @@+# Revision history for applicative-logic++## 0.1.0.0 -- YYYY-mm-dd++* First version. Released on an unsuspecting world.
+ LICENSE view
@@ -0,0 +1,30 @@+Copyright (c) 2024, Håkon Gylterud++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 Håkon Gylterud 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.
+ applicative-logic.cabal view
@@ -0,0 +1,28 @@+cabal-version: 3.0+name: applicative-logic+version: 0.1.0.1+synopsis:+ Generalized logic operations for Applicative and Alternative functors++-- description:+homepage: http://hakon.gylterud.net/programming/applicative-logic+license: BSD-3-Clause+license-file: LICENSE+author: Håkon Robbestad Gylterud+maintainer: lyesveasp@openbastille.org+-- copyright:+category: Control+build-type: Simple+extra-doc-files: CHANGELOG.md+-- extra-source-files:++common warnings+ ghc-options: -Wall++library+ import: warnings+ exposed-modules: Control.Applicative.Logic+ build-depends: base >=4.1 && <4.21+ hs-source-dirs: src+ default-language: Haskell2010+
+ src/Control/Applicative/Logic.hs view
@@ -0,0 +1,73 @@+module Control.Applicative.Logic (any,or,all,and,(&&),convert,Searchable,search) where++import Control.Applicative+import Prelude hiding (any,all,and,or,(&&))++true :: (Applicative f, Monoid a) => f a+true = pure mempty++false :: (Alternative f) => f a+false = empty++-- | 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 . ((<|>) .)++-- | Generalized version of 'Prelude.all'. It takes a predicate that gives generalized+-- 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 (<>) <$>)+++-- | 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+-- @+and :: (Applicative f, Monoid a, Foldable t)+ => t (f a) -> f a+and = all id++(&&) :: (Applicative f, Monoid a)+ => f a -> f a -> f a+(&&) = liftA2 (<>)++-- | 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++class (Foldable t) => Searchable t where+ search :: (Alternative f, Monoid b) => (a -> f b) -> t a -> f b++instance Searchable Maybe where+ search = any++