applicable 0.4.0.0 → 0.4.1.0
raw patch · 3 files changed
+68/−44 lines, 3 filesdep ~basePVP ok
version bump matches the API change (PVP)
Dependency ranges changed: base
API changes (from Hackage documentation)
+ Data.Applicable: BiFlApp :: f (a -> b) (a -> c) -> BiFlapApply f a b c
+ Data.Applicable: FlApp :: f (a -> b) -> FlapApply f a b
+ Data.Applicable: [unBiFlApp] :: BiFlapApply f a b c -> f (a -> b) (a -> c)
+ Data.Applicable: [unFlApp] :: FlapApply f a b -> f (a -> b)
+ Data.Applicable: instance Data.Bifunctor.Bifunctor f => Data.Applicable.Applicable (Data.Applicable.BiFlapApply f a b c) a (f b c)
+ Data.Applicable: instance GHC.Base.Functor f => Data.Applicable.Applicable (Data.Applicable.FlapApply f a b) a (f b)
+ Data.Applicable: instance GHC.Base.Functor f => GHC.Base.Functor (Data.Applicable.FlapApply f a)
+ Data.Applicable: instance GHC.Generics.Generic (Data.Applicable.BiFlapApply f a b c)
+ Data.Applicable: instance GHC.Generics.Generic (Data.Applicable.FlapApply f a b)
+ Data.Applicable: newtype BiFlapApply f a b c
+ Data.Applicable: newtype FlapApply f a b
Files
- CHANGELOG.md +8/−1
- Data/Applicable.hs +58/−41
- applicable.cabal +2/−2
CHANGELOG.md view
@@ -1,12 +1,19 @@ # Revision history for applicable +## 0.4.1.0 -- 2022-07-17++* Added `FlapApply` and `BiFlapApply`.+* Slightly revised changelog.+* Slightly revised documentation.+* Reformatted source code.+ ## 0.4.0.0 -- 2022-06-27 * Fixed missing instances from 0.3.0.0. ## 0.3.0.0 -- 2022-06-27 -* Added more instances.+* Added more newtypes and instances. ## 0.2.0.0 -- 2022-06-27
Data/Applicable.hs view
@@ -1,39 +1,40 @@-{-# OPTIONS_HADDOCK show-extensions #-}-{-# LANGUAGE FunctionalDependencies #-}+{-# LANGUAGE DeriveDataTypeable #-}+{-# LANGUAGE DeriveGeneric #-}+{-# LANGUAGE DeriveTraversable #-} {-# LANGUAGE FlexibleInstances #-}+{-# LANGUAGE FunctionalDependencies #-} {-# LANGUAGE GeneralizedNewtypeDeriving #-}-{-# LANGUAGE DeriveTraversable #-}-{-# LANGUAGE DeriveGeneric #-}-{-# LANGUAGE DeriveDataTypeable #-}--{- |-Module: Data.Applicable-Description: The 'Applicable' class-Copyright: ⓒ 2022 Anselm Schüler-License: MIT-Maintainer: mail@anselmschueler.com--The 'Applicable' class with its operator '($*)'.-You will likely need the @FlexibleContexts@ extension to use this module’s instances.--}+{-# OPTIONS_HADDOCK show-extensions #-} -module Data.Applicable (- Applicable(..),- ApplyTo(..),- ApplyMap(..),- ApplyAp(..),- ApplyBind(..),- GroupAction(..),- ChurchBool(..),- ChurchNumeral(..),- ChurchTuple(..)-) where+-- |+-- Module: Data.Applicable+-- Description: The 'Applicable' class+-- Copyright: ⓒ 2022 Anselm Schüler+-- License: MIT+-- Maintainer: mail@anselmschueler.com+--+-- The 'Applicable' class with its operator '($*)'.+-- You will likely need the @FlexibleContexts@ extension to use this module’s instances.+module Data.Applicable+ ( Applicable (..),+ ApplyTo (..),+ FlapApply (..),+ BiFlapApply (..),+ ApplyMap (..),+ ApplyAp (..),+ ApplyBind (..),+ GroupAction (..),+ ChurchBool (..),+ ChurchNumeral (..),+ ChurchTuple (..),+ )+where +import Data.Bifunctor (Bifunctor (bimap))+import Data.Data (Data)+import Data.Ix (Ix) import Data.List (genericIndex)-import Data.Bifunctor (Bifunctor)-import Data.Ix-import Data.Data-import GHC.Generics+import GHC.Generics (Generic) -- | A class for types whose values can be applied. -- Instances are required to be uniquely determined by the applied and applied-to type.@@ -45,36 +46,52 @@ f $* x = f x -- | A wrapper for values.--- Can be applied to a function '(GHC.Types.->)', applying the function to the inner value.-newtype ApplyTo a = AppTo { unAppTo :: a } deriving (Generic, Data, Eq, Ord, Show, Read, Ix, Functor, Foldable, Traversable)+-- Can be applied to a function, applying the function to the value.+newtype ApplyTo a = AppTo {unAppTo :: a} deriving (Generic, Data, Eq, Ord, Show, Read, Ix, Functor, Foldable, Traversable) instance Applicable (ApplyTo a) (a -> b) b where AppTo x $* f = f x +-- | A wrapper for functions wrapped in a 'Functor'.+-- Can be applied to a value, 'fmap'-ing the application over the 'Functor'.+--+-- This nomenclature is borrowed from @relude@.+newtype FlapApply f a b = FlApp {unFlApp :: f (a -> b)} deriving (Generic, Functor)++instance Functor f => Applicable (FlapApply f a b) a (f b) where+ FlApp fs $* x = ($ x) <$> fs++-- | A wrapper for functions wrapped in a 'Bifunctor'.+-- Can be applied to a value, 'bimap'-ing the application over both fields.+newtype BiFlapApply f a b c = BiFlApp {unBiFlApp :: f (a -> b) (a -> c)} deriving Generic++instance Bifunctor f => Applicable (BiFlapApply f a b c) a (f b c) where+ BiFlApp fs $* x = bimap ($ x) ($ x) fs+ -- | A wrapper for functions. -- Can be applied to a 'Functor', 'fmap'-ing the function over the inner values.-newtype ApplyMap a b = AppMap { unAppMap :: a -> b } deriving (Generic, Functor)+newtype ApplyMap a b = AppMap {unAppMap :: a -> b} deriving (Generic, Functor) instance Functor f => Applicable (ApplyMap a b) (f a) (f b) where AppMap f $* xa = f <$> xa -- | A wrapper for functions in an applicative functor. -- Can be applied to an 'Applicative' functor, '(<*>)'-ing it on it.-newtype ApplyAp f a b = AppAp { unAppAp :: f (a -> b) } deriving (Generic, Functor)+newtype ApplyAp f a b = AppAp {unAppAp :: f (a -> b)} deriving (Generic, Functor) instance Applicative f => Applicable (ApplyAp f a b) (f a) (f b) where AppAp f $* xa = f <*> xa -- | A wrapper for 'Control.Arrow.Kleisli' arrows. -- Can be applied to a 'Monad', '(>>=)'-ing it on it.-newtype ApplyBind m a b = AppBind { unAppBind :: a -> m b } deriving (Generic, Functor)+newtype ApplyBind m a b = AppBind {unAppBind :: a -> m b} deriving (Generic, Functor) instance Monad m => Applicable (ApplyBind m a b) (m a) (m b) where AppBind f $* xa = xa >>= f -- | A wrapper for 'Semigroup' members, representing the associated group action. -- Can be applied to another member, '(<>)'-ing them.-newtype GroupAction a = GrpAct { unGrpAct :: a } deriving (Generic, Data, Eq, Ord, Show, Read, Ix, Functor, Foldable, Traversable)+newtype GroupAction a = GrpAct {unGrpAct :: a} deriving (Generic, Data, Eq, Ord, Show, Read, Ix, Functor, Foldable, Traversable) instance Semigroup a => Applicable (GroupAction a) a a where GrpAct a $* b = a <> b@@ -83,7 +100,7 @@ -- When applied to a value, uses the Church encoding of Booleans. -- The Church encoding of Booleans is a binary function -- that returns its first argument for 'True', and its second for 'False'.-newtype ChurchBool = ChBool { unChBool :: Bool } deriving (Generic, Data, Eq, Ord, Show, Read, Ix)+newtype ChurchBool = ChBool {unChBool :: Bool} deriving (Generic, Data, Eq, Ord, Show, Read, Ix) instance Applicable ChurchBool a (a -> a) where ($*) (ChBool True) t _ = t@@ -93,10 +110,10 @@ mapChBool :: (Bool -> Bool) -> ChurchBool -> ChurchBool mapChBool f (ChBool x) = ChBool $ f x --- | A wrapper for natural numbers (Approximated by 'Integral').+-- | A wrapper for natural numbers (approximated by 'Integral'). -- When applied to a value, uses the Church encoding of natural numbers. -- Church numerals represent the number _n_ as a function that take another function and repeatedly applies it _n_ times.-newtype ChurchNumeral a = ChNum { unChNum :: a } deriving (Generic, Data, Eq, Ord, Show, Read, Ix, Functor, Foldable, Traversable)+newtype ChurchNumeral a = ChNum {unChNum :: a} deriving (Generic, Data, Eq, Ord, Show, Read, Ix, Functor, Foldable, Traversable) instance Integral a => Applicable (ChurchNumeral a) (a -> a) (a -> a) where ($*) (ChNum n) f x = genericIndex (iterate f x) n@@ -104,7 +121,7 @@ -- | A wrapper for tuples '(,)'. -- When applied to a value, uses the Church encoding of tuples. -- The Church encoding of tuples applies a function to the values inside a tuple.-newtype ChurchTuple a b = ChTup { unChTup :: (a, b) } deriving (Generic, Data, Eq, Ord, Show, Read, Ix, Functor, Foldable, Traversable, Bifunctor)+newtype ChurchTuple a b = ChTup {unChTup :: (a, b)} deriving (Generic, Data, Eq, Ord, Show, Read, Ix, Functor, Foldable, Traversable, Bifunctor) instance Applicable (ChurchTuple a b) (a -> b -> c) c where ChTup (x, y) $* f = f x y
applicable.cabal view
@@ -1,6 +1,6 @@ cabal-version: 2.4 name: applicable-version: 0.4.0.0+version: 0.4.1.0 synopsis: A class for things that can be applied description: A class for things that can be applied, and utility newtypes homepage: https://github.com/schuelermine/applicable@@ -16,5 +16,5 @@ library exposed-modules: Data.Applicable- build-depends: base >=4.14 && <=4.16+ build-depends: base >=4.14 && <=5 default-language: Haskell2010