[Haskell-cafe] Re: Full strict functor by abusing Haskell exceptions

Paolo G. Giarrusso p.giarrusso at gmail.com
Mon Sep 13 18:23:23 EDT 2010

On Sep 13, 6:25 pm, Maciej Piechotka <uzytkown... at gmail.com> wrote:
> I started experiment with strict functors. I come to:

> > import Control.Exception
> > import Foreign
> > import Prelude hiding (catch)
> > data StrictMonad a = StrictMonad a deriving Show
> > instance Functor StrictMonad where
> >     f `fmap` StrictMonad v = return $ f v
> > instance Applicative StrictMonad where
> >     pure = return
> >     (<*>) = ap
> > instance Monad StrictMonad where
> >     return x = unsafePerformIO $ do
> >         (return $! x) `catch` \(SomeException _) -> return x
> >         return $! StrictMonad x
> >     StrictMonad v >>= f = f v
> It seems to be valid IMHO Functor and Monad (I haven't prove it) as long
> as functions terminates.

Here, I just believe you, and assume you mean that some non-
terminating function would give problems to your strict functor, i.e.
it wouldn't satisfy the functor/monad laws.

Then, I also wonder if the functor you have is any different from an
identity functor - I see why the monad could be strict.

> Some time ago there was post stating that there is not possible strict
> 'interesting' functor - I guess that the above is 'interesting' (and due
> to halting problem I guess it is not possible to create strict Functor
> which would deal with that problem).

I'm no expert, but since a functor on the Hask category must work on
all functions available there, it looks like you "proved" that yours
is not a functor and can't be fixed; maybe, that means that no strict
functor exist. Your function is probably valid in a different
category, containing mostly the same objects but just total functions
- if it is a valid category; I wonder what would happen when arrows in
this category were applied on undefined, but maybe this means that
objects in this category should not contain undefined as an element;
at that point, you are in a strongly normalizing programming language
and probably "strict" makes no sense.

Then, I would also like to understand what exactly a strict functor
is, in detail, and/or a link to the post you reference.
Best regards


More information about the Haskell-Cafe mailing list