FactoryArrow

I’ve been playing around with an Arrow concept, which to my knowledge is original. I’ve decided to call this a FactoryArrow:


newtype FactoryArrow m n a b = FactoryArrow { runFactory :: m (Kleisli n a b) }

Where m and n are Monads. m is a single-pass initialization monad, while n is a multiple-pass working monad. The arrow supports all of the standard accessory arrow typeclasses, including ArrowLoop if n implements MonadFix, and ArrowApply if m and n are the same.

This arrow simply captures a two-phase initialize-and-run design pattern.

To the best of my imagination, there cannot be a corresponding useful FactoryMonad. I would be extremely interested if anyone can contradict me on that point.

My current interest is in using the FactoryArrow as a replacement for the mealy-style arrows by using IORefs (or potentially even STM transaction variables) to store automaton states instead of unevaluated thunks.

The corresponding implementation as of the time of this writing.

Advertisement

About Christopher Lane Hinson

A hairy Haskell hacker and developer of Roguestar, a 3D science fiction roguelike game.
This entry was posted in Haskell, RSAGL. Bookmark the permalink.

2 Responses to FactoryArrow

  1. Any Arrow wrapped in an Applicative gives another arrow

    newtype ApArrow f (~>) a b = ApArrow { runApArrow :: f (a ~> b) }

    Since every Monad is also an Applicative functor, your FactoryArrow m n = ApArrow m (Kleisli n)

  2. Lane says:

    Are you talking about the StaticArrow?

    I see it. Good catch.

Leave a Reply

Fill in your details below or click an icon to log in:

Gravatar
WordPress.com Logo

Please log in to WordPress.com to post a comment to your blog.

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s