Skip to content

Instantly share code, notes, and snippets.

@raichoo
Created October 24, 2011 17:50
Show Gist options
  • Save raichoo/1309631 to your computer and use it in GitHub Desktop.
Save raichoo/1309631 to your computer and use it in GitHub Desktop.
fix
import Control.Applicative
import Control.Monad.Fix
data CounterRep = CounterRep { x :: Int }
data Counter = Counter { get :: Int,
set :: Int -> Counter,
inc :: Counter }
counterClass = \rep ->
\this ->
Counter { get = x rep,
set = newCounter,
inc = newCounter $ (get this) + 1 }
newCounter x = fix (counterClass $ CounterRep x)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment