Skip to content

Instantly share code, notes, and snippets.

@eric-corumdigital
Created June 13, 2018 20:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eric-corumdigital/bd007b9b8abe5bf270a6df5c84009b3f to your computer and use it in GitHub Desktop.
Save eric-corumdigital/bd007b9b8abe5bf270a6df5c84009b3f to your computer and use it in GitHub Desktop.
Incremental functions category draft (PS)
type Jet a = { position :: a, velocity :: Change a }
destination :: forall a da. Patch a da => Jet a -> a
destination {position, velocity} = patch position (fromChange velocity)
newtype Incremental a b = Incremental (Jet a -> Jet b)
-- | Construct an incremental function from a function on Jets. The user must
-- | verify that these laws hold:
-- |
-- | - `∀fxy. destination x = destination y ⇒ destination (f x) = destination (f y)`
-- | - `∀fxy. x.position = y.position ⇒ (f x).position = (f y).position`
incremental :: forall a b. (Jet a -> Jet b) -> Incremental a b
incremental = Incremental
instance semigroupoidIncremental :: Semigroupoid Incremental where
compose (Incremental f) (Incremental g) = Incremental (compose f g)
instance categoryIncremental :: Category Incremental where
identity = Incremental identity
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment