newtype 0.1 → 0.2
raw patch · 2 files changed
+17/−2 lines, 2 files
Files
- Control/Newtype.hs +16/−1
- newtype.cabal +1/−1
Control/Newtype.hs view
@@ -12,7 +12,7 @@ This package includes 'Newtype' instances for all the (non-GHC\/foreign) newtypes in base (as seen in the examples). However, there are neat things you can do with this with /any/ newtype and you should definitely define your own 'Newtype' instances for the power of this library. For example, see @ala Cont traverse@, with the proper 'Newtype' instance for Cont. -}-module Control.Newtype ( Newtype(..), op, ala, ala', under ) where+module Control.Newtype ( Newtype(..), op, ala, ala', under, over, underF, overF ) where import Data.Monoid import Control.Applicative@@ -57,7 +57,18 @@ under :: (Newtype n o, Newtype n' o') => (o -> n) -> (n -> n') -> (o -> o') under _ f = unpack . f . pack +-- | The opposite of 'under'. I.e., take a function which works on the underlying types, and switch it to a function that works on the newtypes.+over :: (Newtype n o, Newtype n' o') => (o -> n) -> (o -> o') -> (n -> n')+over _ f = pack . f . unpack +-- | 'under' lifted into a Functor.+underF :: (Newtype n o, Newtype n' o', Functor f) => (o -> n) -> (f n -> f n') -> (f o -> f o')+underF _ f = fmap unpack . f . fmap pack++-- | 'over' lifted into a Functor.+overF :: (Newtype n o, Newtype n' o', Functor f) => (o -> n) -> (f o -> f o') -> (f n -> f n')+overF _ f = fmap pack . f . fmap unpack+ instance Newtype All Bool where pack = All unpack (All a) = a@@ -74,6 +85,10 @@ pack = Product unpack (Product a) = a +instance Newtype (Kleisli m a b) (a -> m b) where+ pack = Kleisli+ unpack (Kleisli a) = a+ instance Newtype (WrappedMonad m a) (m a) where pack = WrapMonad unpack (WrapMonad a) = a
newtype.cabal view
@@ -1,5 +1,5 @@ Name: newtype-Version: 0.1+Version: 0.2 Synopsis: A typeclass and set of functions for working with newtypes. Description: Per Conor McBride, the Newtype typeclass represents the packing and unpacking of a newtype, and allows you to operatate under that newtype with functions such as ala. License: BSD3