Skip to content

Instantly share code, notes, and snippets.

@harpocrates
Created January 28, 2018 19:28
Show Gist options
  • Save harpocrates/cfaf8c45092e17239d7cdcc172e90975 to your computer and use it in GitHub Desktop.
Save harpocrates/cfaf8c45092e17239d7cdcc172e90975 to your computer and use it in GitHub Desktop.
Multi-stage TH
-- Notice how flipping the order of anything makes this not
-- compile - this demonstrates that GHC is doing the following
-- in order:
--
-- 1. Processing the `foo` declaration
-- 2. Processing the `bar` declaration
-- 3. Processing the `baz` declaration
--
-- So GHC is already doing multiple passes, right?
```haskell
{-# LANGUAGE TemplateHaskell, QuasiQuotes #-}
$([d| foo = (+1) |])
bar = foo
$([d| baz = bar . (+2) |])
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment