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

Maciej Piechotka uzytkownik2 at gmail.com
Mon Sep 13 12:25:53 EDT 2010


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.

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).

Regards
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: This is a digitally signed message part
Url : http://www.haskell.org/pipermail/haskell-cafe/attachments/20100913/58b78dad/attachment.bin


More information about the Haskell-Cafe mailing list