Skip to content

Instantly share code, notes, and snippets.

View mattgreen's full-sized avatar
💭
Status is a trap.

Matt Green mattgreen

💭
Status is a trap.
View GitHub Profile
@mattgreen
mattgreen / States-v3.md
Created June 24, 2021 14:59 — forked from andymatuschak/States-v3.md
A composable pattern for pure state machines with effects (draft v3)

A composable pattern for pure state machines with effects

State machines are everywhere in interactive systems, but they're rarely defined clearly and explicitly. Given some big blob of code including implicit state machines, which transitions are possible and under what conditions? What effects take place on what transitions?

There are existing design patterns for state machines, but all the patterns I've seen complect side effects with the structure of the state machine itself. Instances of these patterns are difficult to test without mocking, and they end up with more dependencies. Worse, the classic patterns compose poorly: hierarchical state machines are typically not straightforward extensions. The functional programming world has solutions, but they don't transpose neatly enough to be broadly usable in mainstream languages.

Here I present a composable pattern for pure state machiness with effects,

Keybase proof

I hereby claim:

  • I am mattgreen on github.
  • I am mattgreen (https://keybase.io/mattgreen) on keybase.
  • I have a public key ASBEBkqCkX13f3fBRoxqoiotAy5Gw-aCxRxvxiAV5DzTTAo

To claim this, I am signing this object:

leftPad :: Int -> String -> String
leftPad n x
| length x >= n = x
| otherwise = padding ++ x
where
padding = replicate (n - length x) ' '
import Control.Monad (guard)
import Data.List (foldl', sort)
-- Types
data Player = Player Name Rating
deriving (Eq, Show)
type Name = String
type Rating = Integer
@mattgreen
mattgreen / frp.md
Last active August 29, 2015 14:25 — forked from ohanhi/frp.md
Learning FP the hard way: Experiences on the Elm language

Learning FP the hard way: Experiences on the Elm language

by Ossi Hanhinen, @ohanhi

with the support of Futurice 💚.

Licensed under CC BY 4.0.

Foreword

For example, one of the many current day standards that was dismissed immediately is the WWW (one could hardly imagine more of a mess).

But the functionality plus more can be replaced in our "ideal world" with encapsulated confined migratory VMs ("Internet objects") as a kind of next version of Gerry Popek's LOCUS.

The browser and other storage confusions are all replaced by the simple idea of separating out the safe objects from the various modes one uses to send and receive them. This covers files, email, web browsing, search engines, etc. What is left in this model is just a UI that can integrate the visual etc., outputs from the various encapsulated VMs, and send them events to react to. (The original browser folks missed that a scalable browser is more like a kernel OS than an App)

These are old ideas, but the vendors etc didn't get it ...