[Haskell-cafe] Pointless functors

Robin Green greenrd at greenrd.org
Thu Mar 12 22:43:39 EDT 2009


On Fri, 13 Mar 2009 14:32:23 +0000
Ross Paterson <ross at soi.city.ac.uk> wrote:

> On Fri, Mar 13, 2009 at 03:18:15PM +0100, Martijn van Steenbergen
> wrote:
> > Are there any functors f for which no point/pure/return :: a -> f a
> > exists?
> 
> No.  Choose an arbitrary element shape :: f () and define
> 
>         point x = fmap (const x) shape

This suggests a fun way to define a monad for a functor F:

-- Does nothing, has no effect, and returns ()
noOp :: F ()
noOp = ...

instance Monad F where
  return x = fmap (const x) noOp
  (<<=) f x = ...

I think noOp would be a nice addition to the Monad class, as well.
-- 
Robin


More information about the Haskell-Cafe mailing list