I'm still getting familiar with all this category theory stuff, and just about every example I see is with a Maybe or an Array. But I haven't found any examples that discriminate between these categories. For example, here are some of the questions I've still been unable to answer:
I'm learning this stuff through the context of JavaScript FantasyLand so that's where I'm getting the lingo from -- I understand there are different words for these things.
The five social areas are: employment, housing, services, unions and vocational associations and contracts. Discrimination based on 17 different personal attributes – called grounds – is against the law under the Code.
Indirect discrimination When people are unaware that they are being discriminatory or do not intend to be, this is one of the most common types of discrimination because at times you may make decisions or put in place business practices without thinking to consider those with protected characteristics.
Cactus gives a great example of a semigroup that's not a monoid. Non-empty (finite) lists of any type represent the free semigroup over that type. Another example is Data.Void.Void
, which isn't a Monoid
because it doesn't have any elements and therefore doesn't have an identity element. Yet another example is the set of positive integers under addition.
One Functor
that's not an Apply
is Handler
.
data Handler a where
Handler :: Exception e => (e -> IO a) -> Handler a
instance Functor Handler where
fmap f (Handler h) = Handler (\e -> f <$> h e)
Given Handler f :: Handler (a -> b)
and Handler g :: Handler a
, you have
f :: e1 -> IO (a -> b)
g :: e2 -> IO a
Where e1
and e2
are (possibly different) types of exception. You need to create h :: e3 -> IO b
for some exception type e3
. There is no really sensible way to do this**.
It seems harder to find Functor
s that can't be made into law-abiding Apply
instances, because Apply
has just one law and therefore admits all sorts of weird things that Applicative
would reject.
Map k
and IntMap
. Also, (,) a
and Const a
when a
is a Semigroup
but not a Monoid
. Similarly, some other types fit the pattern of accepting a weaker context for Apply
and/or Bind
than for Applicative
or Monad
, respectively.
ZipList
is an Apply
but not a Bind
. I don't know what a Chain
is.
** One semi-sensible way might look like this:
data P x y = P x y deriving (Show, Typeable)
instance (Exception x, Exception y) =>
Exception (P x y)
instance Apply Handler where
Handler f <.> Handler g =
Handler (\(P e1 e2) -> f e1 <*> g e2)
I think this obeys the Apply
law, but I'm not yet completely certain.
Non-empty lists, defined as data NEList a = Cons a [a]
are semigroups but not monoids.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With