-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | A typeclass and set of functions for working with newtypes -- -- Per Conor McBride, the Newtype typeclass represents the packing and -- unpacking of a newtype, and allows you to operate under that newtype -- with functions such as ala. Generics support was added in version 0.4, -- making this package a full replacement for the original newtype -- package, and a better alternative to newtype-th. @package newtype-generics @version 0.6 -- | The Newtype typeclass and related functions. Primarily pulled -- from Conor McBride's Epigram work. Some examples: -- --
--   >>> ala Sum foldMap [1,2,3,4]
--   10
--   
-- --
--   >>> ala Endo foldMap [(+1), (+2), (subtract 1), (*2)] 3
--   8
--   
-- --
--   >>> under2 Min (<>) 2 1
--   1
--   
-- --
--   >>> over All not (All False)
--   All {getAll = True)
--   
-- -- 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. You can easily -- define new instances for your newtypes with the help of GHC.Generics -- --
--   import GHC.Generics
--   
--   (...)
--   newtype Example = Example Int
--     deriving (Generic)
--   
--   instance Newtype Example
--   
-- -- This avoids the use of Template Haskell (TH) to get new instances. module Control.Newtype.Generics -- | As long as the type n is an instance of Generic, you can -- create an instance with just instance Newtype n class Newtype n where { type family O n :: Type; type O n = GO (Rep n); } pack :: Newtype n => O n -> n pack :: (Newtype n, Generic n, GNewtype (Rep n), O n ~ GO (Rep n)) => O n -> n unpack :: Newtype n => n -> O n unpack :: (Newtype n, Generic n, GNewtype (Rep n), O n ~ GO (Rep n)) => n -> O n -- | This function serves two purposes: -- --
    --
  1. Giving you the unpack of a newtype without you needing to remember -- the name.
  2. --
  3. Showing that the first parameter is completely ignored on -- the value level, meaning the only reason you pass in the constructor -- is to provide type information. Typeclasses sure are neat.
  4. --
-- --
--   >>> op Identity (Identity 3)
--   3
--   
op :: (Newtype n, o ~ O n) => (o -> n) -> n -> o -- | The workhorse of the package. Given a "packer" and a "higher order -- function" (hof), it handles the packing and unpacking, and just -- sends you back a regular old function, with the type varying based on -- the hof you passed. -- -- The reason for the signature of the hof is due to ala -- not caring about structure. To illustrate why this is important, -- consider this alternative implementation of under2: -- --
--   under2 :: (Newtype n, Newtype n', o' ~ O n', o ~ O n)
--          => (o -> n) -> (n -> n -> n') -> (o -> o -> o')
--   under2' pa f o0 o1 = ala pa (\p -> uncurry f . bimap p p) (o0, o1)
--   
-- -- Being handed the "packer", the hof may apply it in any -- structure of its choosing – in this case a tuple. -- --
--   >>> ala Sum foldMap [1,2,3,4]
--   10
--   
ala :: (Newtype n, Newtype n', o' ~ O n', o ~ O n) => (o -> n) -> ((o -> n) -> b -> n') -> b -> o' -- | This is the original function seen in Conor McBride's work. The way it -- differs from the ala function in this package, is that it -- provides an extra hook into the "packer" passed to the hof. However, -- this normally ends up being id, so ala wraps this -- function and passes id as the final parameter by default. If -- you want the convenience of being able to hook right into the hof, you -- may use this function. -- --
--   >>> ala' Sum foldMap length ["hello", "world"]
--   10
--   
-- --
--   >>> ala' First foldMap (readMaybe @Int) ["x", "42", "1"]
--   Just 42
--   
ala' :: (Newtype n, Newtype n', o' ~ O n', o ~ O n) => (o -> n) -> ((a -> n) -> b -> n') -> (a -> o) -> b -> o' -- | A very simple operation involving running the function 'under' the -- newtype. -- --
--   >>> under Product (stimes 3) 3
--   27
--   
under :: (Newtype n, Newtype n', o' ~ O n', o ~ O n) => (o -> n) -> (n -> n') -> o -> o' -- | 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 All not (All False)
--   All {getAll = True}
--   
over :: (Newtype n, Newtype n', o' ~ O n', o ~ O n) => (o -> n) -> (o -> o') -> n -> n' -- | Lower a binary function to operate on the underlying values. -- --
--   >>> under2 Any (<>) True False
--   True
--   
under2 :: (Newtype n, Newtype n', o' ~ O n', o ~ O n) => (o -> n) -> (n -> n -> n') -> o -> o -> o' -- | The opposite of under2. over2 :: (Newtype n, Newtype n', o' ~ O n', o ~ O n) => (o -> n) -> (o -> o -> o') -> n -> n -> n' -- | under lifted into a Functor. underF :: (Newtype n, Newtype n', o' ~ O n', o ~ O n, Functor f, Functor g) => (o -> n) -> (f n -> g n') -> f o -> g o' -- | over lifted into a Functor. overF :: (Newtype n, Newtype n', o' ~ O n', o ~ O n, Functor f, Functor g) => (o -> n) -> (f o -> g o') -> f n -> g n' instance Control.Newtype.Generics.Newtype (Control.Applicative.WrappedMonad m a) instance Control.Newtype.Generics.Newtype (Control.Applicative.WrappedArrow a b c) instance Control.Newtype.Generics.Newtype (Control.Applicative.ZipList a) instance Control.Newtype.Generics.Newtype (Control.Arrow.Kleisli m a b) instance Control.Newtype.Generics.Newtype (Control.Arrow.ArrowMonad a b) instance Control.Newtype.Generics.Newtype (Data.Fixed.Fixed a) instance Control.Newtype.Generics.Newtype (Data.Functor.Compose.Compose f g a) instance Control.Newtype.Generics.Newtype (Data.Functor.Const.Const a x) instance Control.Newtype.Generics.Newtype (Data.Functor.Identity.Identity a) instance Control.Newtype.Generics.Newtype (Data.Semigroup.Internal.Dual a) instance Control.Newtype.Generics.Newtype (Data.Semigroup.Internal.Endo a) instance Control.Newtype.Generics.Newtype Data.Semigroup.Internal.All instance Control.Newtype.Generics.Newtype Data.Semigroup.Internal.Any instance Control.Newtype.Generics.Newtype (Data.Semigroup.Internal.Sum a) instance Control.Newtype.Generics.Newtype (Data.Semigroup.Internal.Product a) instance Control.Newtype.Generics.Newtype (Data.Monoid.First a) instance Control.Newtype.Generics.Newtype (Data.Monoid.Last a) instance Control.Newtype.Generics.Newtype (Data.Semigroup.Internal.Alt f a) instance Control.Newtype.Generics.Newtype (Data.Monoid.Ap f a) instance Control.Newtype.Generics.Newtype (Data.Ord.Down a) instance Control.Newtype.Generics.Newtype (Data.Semigroup.Min a) instance Control.Newtype.Generics.Newtype (Data.Semigroup.Max a) instance Control.Newtype.Generics.Newtype (Data.Semigroup.First a) instance Control.Newtype.Generics.Newtype (Data.Semigroup.Last a) instance Control.Newtype.Generics.Newtype (Data.Semigroup.WrappedMonoid m) instance Control.Newtype.Generics.Newtype (Data.Semigroup.Option a) instance Control.Newtype.Generics.GNewtype (GHC.Generics.D1 d (GHC.Generics.C1 c (GHC.Generics.S1 s (GHC.Generics.K1 i a))))