Skip to content

Instantly share code, notes, and snippets.

@Porges
Last active August 26, 2019 01:43
Show Gist options
  • Save Porges/c8b5f8844ef9892d3b29c47c412edb0e to your computer and use it in GitHub Desktop.
Save Porges/c8b5f8844ef9892d3b29c47c412edb0e to your computer and use it in GitHub Desktop.
{-# LANGUAGE GADTs, RecordWildCards #-}
import Data.Monoid
data DFA a r where
DFA :: { transition :: a -> Endo s, initial :: s, result :: s -> r } -> DFA a r
run :: Foldable f => DFA a r -> f a -> r
run DFA{..} input = result (foldMap transition input `appEndo` initial)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment