acme-functors-0.1.0.0: The best applicative functors.

Acme.Functors

Description

Types are great. Lifting them into some sort of applicative functor makes them even better. This module is an homage to our favorite applicatives, and to the semigroups with which they are instrinsically connected.

Synopsis

# Lifted-but-why

data LiftedButWhy a Source #

LiftedButWhy is a boring functor that just has one value and no other structure or interesting properties.

Constructors

 LiftedButWhy a A value that has been lifted for some damned reason.... Okay, to be honest, this one is nobody's favorite, but it is included here for completeness.

Instances

# Two

data Two a Source #

Two is two values. Yep. Just two values.

Constructors

 Two FieldsfirstOfTwo :: aOne value.secondOfTwo :: aAnother value.

Instances

 Source # Methodsfmap :: (a -> b) -> Two a -> Two b #(<$) :: a -> Two b -> Two a # Source # If you have two functions f and g and two values a and a', then you can apply them with (<*>) to get two results f a and g a'.pure a = Two a a Two f g <*> Two a a' = Two (f a) (g a') Methodspure :: a -> Two a #(<*>) :: Two (a -> b) -> Two a -> Two b #(*>) :: Two a -> Two b -> Two b #(<*) :: Two a -> Two b -> Two a # Eq a => Eq (Two a) Source # Methods(==) :: Two a -> Two a -> Bool #(/=) :: Two a -> Two a -> Bool # Show a => Show (Two a) Source # MethodsshowsPrec :: Int -> Two a -> ShowS #show :: Two a -> String #showList :: [Two a] -> ShowS # Semigroup a => Semigroup (Two a) Source # Two x y <> Two x' y' = Two (x <> x') (y <> y') Methods(<>) :: Two a -> Two a -> Two a #sconcat :: NonEmpty (Two a) -> Two a #stimes :: Integral b => b -> Two a -> Two a # Monoid a => Monoid (Two a) Source # mempty = Two mempty mempty Methods # Any-number-of data AnyNumberOf a Source # AnyNumberOf starts to get exciting. Any number of values you want. Zero... one ... two ... three ... four ... five ... The possibilities are truly endless. Constructors  OneAndMaybeMore a (AnyNumberOf a) One value, and maybe even more after that! ActuallyNone Oh. Well this is less fun. Instances  Source # Methodsfmap :: (a -> b) -> AnyNumberOf a -> AnyNumberOf b #(<$) :: a -> AnyNumberOf b -> AnyNumberOf a # Source # You can use this to apply any number of functions to any number of arguments.pure a = OneAndMaybeMore a ActuallyNone OneAndMaybeMore f fs <*> OneAndMaybeMore x xs = OneAndMaybeMore (f x) (fs <*> xs) _ <*> _ = ActuallyNoneExample: ( (+ 1) ~~ (* 2) ~~ (+ 5) ~~ ActuallyNone ) <*> ( 1 ~~ 6 ~~ 4 ~~ 37 ~~ ActuallyNone ) = ( 7 ~~ 12 ~~ 9 ~~ ActuallyNone )This example demonstrates how when there are more arguments than functions, any excess arguments (in this case, the 37) are ignored. Methodspure :: a -> AnyNumberOf a #(<*>) :: AnyNumberOf (a -> b) -> AnyNumberOf a -> AnyNumberOf b #(*>) :: AnyNumberOf a -> AnyNumberOf b -> AnyNumberOf b #(<*) :: AnyNumberOf a -> AnyNumberOf b -> AnyNumberOf a # Eq a => Eq (AnyNumberOf a) Source # Methods(==) :: AnyNumberOf a -> AnyNumberOf a -> Bool #(/=) :: AnyNumberOf a -> AnyNumberOf a -> Bool # Show a => Show (AnyNumberOf a) Source # MethodsshowsPrec :: Int -> AnyNumberOf a -> ShowS #show :: AnyNumberOf a -> String #showList :: [AnyNumberOf a] -> ShowS # Source # The operation of combining some number of a with some other number of a is sometimes referred to as zipping.OneAndMaybeMore x xs <> OneAndMaybeMore y ys = OneAndMaybeMore (x <> y) (xs <> ys) _ <> _ = ActuallyNone Methods(<>) :: AnyNumberOf a -> AnyNumberOf a -> AnyNumberOf a #stimes :: Integral b => b -> AnyNumberOf a -> AnyNumberOf a # Monoid a => Monoid (AnyNumberOf a) Source # mempty = mempty ~~ mempty Methods

(~~) :: a -> AnyNumberOf a -> AnyNumberOf a infixr 5 Source #

Alias for OneAndMaybeMore which provides some brevity.

# One-or-more

data OneOrMore a Source #

OneOrMore is more restrictive than AnyNumberOf, yet somehow actually more interesting, because it excludes that dull situation where there aren't any values at all.

Constructors

 OneOrMore FieldstheFirstOfMany :: aDefinitely at least this one.possiblyMore :: AnyNumberOf aAnd perhaps others.

Instances

 Source # Methodsfmap :: (a -> b) -> OneOrMore a -> OneOrMore b #(<$) :: a -> OneOrMore b -> OneOrMore a # Source # pure a = OneOrMore a ActuallyNone OneOrMore f fs <*> OneOrMore x xs = OneOrMore (f x) (fs <*> xs) Methodspure :: a -> OneOrMore a #(<*>) :: OneOrMore (a -> b) -> OneOrMore a -> OneOrMore b #(*>) :: OneOrMore a -> OneOrMore b -> OneOrMore b #(<*) :: OneOrMore a -> OneOrMore b -> OneOrMore a # Eq a => Eq (OneOrMore a) Source # Methods(==) :: OneOrMore a -> OneOrMore a -> Bool #(/=) :: OneOrMore a -> OneOrMore a -> Bool # Show a => Show (OneOrMore a) Source # MethodsshowsPrec :: Int -> OneOrMore a -> ShowS #show :: OneOrMore a -> String #showList :: [OneOrMore a] -> ShowS # Semigroup a => Semigroup (OneOrMore a) Source # OneOrMore a more <> OneOrMore a' more' = OneOrMore a (more <> OneAndMaybeMore a' more') Methods(<>) :: OneOrMore a -> OneOrMore a -> OneOrMore a #sconcat :: NonEmpty (OneOrMore a) -> OneOrMore a #stimes :: Integral b => b -> OneOrMore a -> OneOrMore a # Monoid a => Monoid (OneOrMore a) Source # mempty = OneOrMore mempty ActuallyNone Methods # Also-extra-thing data Also extraThing a Source # Also extraThing is a functor in which each value has an extraThing of some other type that tags along with it. Constructors  Also FieldswithoutExtraThing :: aA value.theExtraThing :: extraThingAn additional thing that tags along. Instances  Functor (Also extraThing) Source # Methodsfmap :: (a -> b) -> Also extraThing a -> Also extraThing b #(<$) :: a -> Also extraThing b -> Also extraThing a # Monoid extraThing => Applicative (Also extraThing) Source # Dragging the extraThing along can be a bit of a burden. It prevents Also extraThing from being an applicative functor — unless the extraThing can pull its weight by bringing a monoid to the table.pure = (Also mempty) (f Also extra1) <*> (a Also extra2) = f a Also (extra1 <> extra2) Methodspure :: a -> Also extraThing a #(<*>) :: Also extraThing (a -> b) -> Also extraThing a -> Also extraThing b #(*>) :: Also extraThing a -> Also extraThing b -> Also extraThing b #(<*) :: Also extraThing a -> Also extraThing b -> Also extraThing a # (Eq extraThing, Eq a) => Eq (Also extraThing a) Source # Methods(==) :: Also extraThing a -> Also extraThing a -> Bool #(/=) :: Also extraThing a -> Also extraThing a -> Bool # (Show extraThing, Show a) => Show (Also extraThing a) Source # MethodsshowsPrec :: Int -> Also extraThing a -> ShowS #show :: Also extraThing a -> String #showList :: [Also extraThing a] -> ShowS # (Semigroup extraThing, Semigroup a) => Semigroup (Also extraThing a) Source # (a Also extra1) <> (a' Also extra2) = (a <> a') Also (extra1 <> extra2) Methods(<>) :: Also extraThing a -> Also extraThing a -> Also extraThing a #sconcat :: NonEmpty (Also extraThing a) -> Also extraThing a #stimes :: Integral b => b -> Also extraThing a -> Also extraThing a # (Monoid extraThing, Monoid a) => Monoid (Also extraThing a) Source # mempty = Also mempty mempty Methodsmempty :: Also extraThing a Source #

data OrInstead otherThing a Source #

OrInstead otherThing is a functor in which, instead of having a value, can actually just have some totally unrelated otherThing instead.

When you combine stuff with (<*>) or (<>), all of the values need to be present. If any of them are the otherThing instead, then the whole expression evaluates to the combination of the otherThings.

Constructors

 NotInstead a Some normal value. Instead otherThing Some totally unrelated other thing.

Instances

# Determined-by-parameter

data DeterminedBy parameter a Source #

DeterminedBy parameter is a value that... well, we're not really sure what it is. We'll find out once a parameter is provided.

The mechanism for deciding how the value is determined from the parameter is opaque; all you can do is test it with different parameters and see what results. There aren't even Eq or Show instances, which is annoying.

Constructors

 Determination ((->) parameter a)

Instances

 Monad (DeterminedBy parameter) Source # Determination fa >>= ff = Determination (\x -> let Determination f = ff (fa x) in f x) Methods(>>=) :: DeterminedBy parameter a -> (a -> DeterminedBy parameter b) -> DeterminedBy parameter b #(>>) :: DeterminedBy parameter a -> DeterminedBy parameter b -> DeterminedBy parameter b #return :: a -> DeterminedBy parameter a #fail :: String -> DeterminedBy parameter a # Functor (DeterminedBy parameter) Source # Methodsfmap :: (a -> b) -> DeterminedBy parameter a -> DeterminedBy parameter b #(<\$) :: a -> DeterminedBy parameter b -> DeterminedBy parameter a # Applicative (DeterminedBy parameter) Source # pure a = Determination (\_ -> a) Determination f <*> Determination a = Determination (\x -> f x (a x)) Methodspure :: a -> DeterminedBy parameter a #(<*>) :: DeterminedBy parameter (a -> b) -> DeterminedBy parameter a -> DeterminedBy parameter b #(*>) :: DeterminedBy parameter a -> DeterminedBy parameter b -> DeterminedBy parameter b #(<*) :: DeterminedBy parameter a -> DeterminedBy parameter b -> DeterminedBy parameter a # Semigroup a => Semigroup (DeterminedBy parameter a) Source # Determination f <> Determination g = Determination (\x -> f x <> g x) Methods(<>) :: DeterminedBy parameter a -> DeterminedBy parameter a -> DeterminedBy parameter a #sconcat :: NonEmpty (DeterminedBy parameter a) -> DeterminedBy parameter a #stimes :: Integral b => b -> DeterminedBy parameter a -> DeterminedBy parameter a # Monoid a => Monoid (DeterminedBy parameter a) Source # mempty = Determination (\_ -> mempty) Methodsmempty :: DeterminedBy parameter a Source #