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

wren ng thornton wren at freegeek.org
Thu Sep 16 00:45:37 EDT 2010

On 9/13/10 6:23 PM, Paolo G. Giarrusso wrote:
> Then, I would also like to understand what exactly a strict functor
> is, in detail, and/or a link to the post you reference.

I'm assuming the OP was referring to a functor for strictness I 
mentioned recently in the discussion about pointed functors. That is,

     newtype Strict a = Strict a

     instance Functor Strict where
         -- This isn't a lawful endofunctor
         fmap f (Strict a) = Strict (f $! a)

     instance Pointed Strict where
         -- This isn't lawful either, as an endofunctor
         point = Strict

The idea being that we make all applications strict. However, that 
definition of fmap isn't lawful because we don't have that fmap(f . g) = 
(fmap f).(fmap g) for all f and g. In particular, it fails when (f . g) 
is bottom eating, i.e. when (g x == _|_) =/=> (f (g x) == _|_).

We can, however, define strict composition:

     (f .! g) x = f $! g x

And we do have that fmap(f .! g) = (fmap f).(fmap g) for Strict. So, 
Strict is a (category theoretic) functor, it's just not an endofunctor 
on Hask.

Given that any functor for adding strictness will have to deal with the 
same issue of preserving bottom-eating compositions, I postulated that 
there exists no functor from (all of) Hask to !Hask. But, since !Hask is 
a subcategory of Hask, it's trivial to go the other direction. In fact, 
the Strict defined above can be considered as the inclusion functor from 
!Hask to Hask by making the strictness of !Hask explicit. This also 
allows Strict to be considered a pointed functor since fmap f . point = 
point . f for strict functions f.

I haven't looked through the suggested code to see if it can actually 
work around the problem.

Live well,

More information about the Haskell-Cafe mailing list