mealy-arrow: Monadic Mealy machines with Arrow, ArrowChoice, and ArrowLoop

[ arrows, bsd3, control, library, program ] [ Propose Tags ] [ Report a vulnerability ]

A monadic Mealy machine in the coalgebraic (continuation-passing) representation: . newtype Auto m a b = Auto { step :: a -> m (b, Auto m a b) } . Each step consumes an input, produces an output in some monad m, and returns the next state as a continuation. The monad parameter controls the effect discipline: Identity for pure machines, IO for effectful ones. . Instances: Category, Arrow, ArrowChoice, ArrowLoop, Profunctor, Functor. Smart constructors: stateless, stateful, constAuto. Natural transformation: hoistAuto. . == How is this different from the mealy package? . The Hackage package mealy provides a pure, existentially-quantified inject/step/extract triple designed for online statistics (moving averages, regression). It has Category and Profunctor instances but no Arrow, no ArrowChoice, no ArrowLoop, and no monadic effects. . mealy-arrow provides the Nu (greatest fixpoint) representation with full Arrow instances and a monad parameter. It is designed for interactive systems: terminal UIs, protocol handlers, game logic, API clients — anything where each step may have effects and the machine's control flow may branch.


[Skip to Readme]

Modules

[Index] [Quick Jump]

Downloads

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees

Candidates

  • No Candidates
Versions [RSS] 0.1.0.0
Change log CHANGELOG.md
Dependencies base (>=4.14 && <5), mealy-arrow, profunctors (>=5.0 && <6) [details]
Tested with ghc ==9.10.3
License BSD-3-Clause
Author mealy-arrow contributors
Maintainer mealy-arrow contributors
Uploaded by kaol at 2026-05-05T08:28:08Z
Category Control, Arrows
Source repo head: git clone https://github.com/mealy-arrow/mealy-arrow
Distributions
Executables mealy-arrow-example
Downloads 3 total (3 in the last 30 days)
Rating (no votes yet) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs available [build log]
Last success reported on 2026-05-05 [all 1 reports]

Readme for mealy-arrow-0.1.0.0

[back to package description]

mealy-arrow

Monadic Mealy machines with Category, Arrow, ArrowChoice, ArrowLoop, and Profunctor instances.

The type

newtype Auto m a b = Auto { step :: a -> m (b, Auto m a b) }

Each step consumes an input, produces an output in monad m, and returns the continuation. The state is the closure — there is no external state type. This is the Nu (greatest fixpoint / final coalgebra) encoding of a Mealy machine.

At Identity it is a pure state machine. At IO it can do effects. The full Arrow stack lets you branch (Either-routing via ArrowChoice), fan (&&&), parallelise (***), and feed back (ArrowLoop with MonadFix).

Quick example

import Control.Arrow.Mealy
import Data.Functor.Identity

counter :: Auto Identity Int Int
counter = stateful 0 $ \total x -> let s = total + x in (s, s)

>>> runIdentity $ stepN counter [1,2,3,4,5]
[1,3,6,10,15]

How is this different from the mealy package?

The Hackage package mealy is a pure, existentially-quantified fold triple for online statistics. It has Category and Profunctor but no Arrow, no effects, no branching. mealy-arrow is for interactive systems where each step may have effects and the control flow may branch.

See also

The mu-nu package builds on mealy-arrow to provide Mu–Nu pairings: pair a finite inspectable tree with an Auto machine, connected by a monoid homomorphism. This enables static analysis of compositional system architecture before execution.