Skip to content

Instantly share code, notes, and snippets.

@tel
Created January 1, 2015 00:53
Show Gist options
  • Save tel/3e79b69da08828236e98 to your computer and use it in GitHub Desktop.
Save tel/3e79b69da08828236e98 to your computer and use it in GitHub Desktop.
CPS causes function composition to flip directions
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE TypeOperators #-}
type b <~ a = forall c . (b -> c) -> a -> c
back :: (a -> b) -> (b <~ a)
back f = (. f)
fwd :: (b <~ a) -> (a -> b)
fwd g = g id
(>>>) :: (a -> b) -> (b -> c) -> (a -> c)
f >>> g = fwd (back f . back g)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment