Are there examples of functors in Haskell which fails to be monads because we cannot implement `return`?

Viewed 188

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.

2 Answers

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:

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.

Related