Skip to content

Instantly share code, notes, and snippets.

@scott-fleischman
Created December 20, 2018 22:34
Show Gist options
  • Save scott-fleischman/9580f60f004280ddd399ac662b39d609 to your computer and use it in GitHub Desktop.
Save scott-fleischman/9580f60f004280ddd399ac662b39d609 to your computer and use it in GitHub Desktop.
DeBruijn Haskell type class
-- https://twitter.com/pigworker/status/1068897189227913223
newtype B t = B t
class DeBruijn d where
deBruijn :: Applicative f => (s -> Int -> f t) -> d s -> Int -> f (d t)
instance DeBruijn B where
deBruijn f (B s) i = B <$> f s (i + 1)
deBruijnDefault = ala' Compose traverse
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment