Translating FRP and Redux into Optics and Recursion Schemes

Derived state for redux Derived state is not equivalent to Indexed state. It could be, but that doesn’t create “legal” (well behaved) traversals. Derived state is equivalent to Coindexed State.

Coindexed and Indexed Optics gives us

  • derived state
  • selectors
  • traversals (reducers)

Redux is a reducer. Catamorphism a la recursion schemes.

Selectors are lenses.

CoFree lets you enrich a data structure. Related to derived data?

Redux actions let you do something similar to writing a free monad. Free monads are interpreted with the catamorphism.

type Stream = Cofree Identity Stream of State hmmm

Stream can sample a function.

data Store a x = Store a (a -> x) is a comonad.

coalgebra can unpack store into a stream.


Indexed functors let you do the recursion scheme thing with annotated/indexed types or polymorphically recursive types. Example of indexed type: types like Vector (length encoded lists). Example of polymorphically recursive types are de-brujin indices, or [1, [2], [[3]], [[[4]]], ...]

Haskell (often or always?) use polymorphic recursion as a solution to the lack of indexed types.

React = traverse render dom