Are there any examples of functors in Haskell which fail to be monads because we cannot implement return
?
I have seen this answer and am inspired by it.
Intuitively it seems that we can always implement return
by using the type constructor. But I must be missing something.
This is exactly what the Bind
typeclass represents: things that have a bind operation, but not necessarily return. Here's some types that are instances of Bind
, but aren't instances of Monad
because they don't have return
:
(,) w
,WriterT w m
, and RWST r w s m
, whenever w
is a Semigroup
but not a Monoid
Map k
, HashMap k
, and IntMap
V1
(note: this is isomorphic to Daniel Wagner's Whoops
and pigworker's Dead
)I guess if there's no constructor, we can't call one:
{-# LANGUAGE EmptyCase #-}
data Whoops a
instance Functor Whoops where fmap f v = case v of
EDIT In fact, this is mentioned at the linked question: have a search for the Dead
type that pigworker uses to show how something can be a functor but not applicative.
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