| 1 | module Foo where |
|---|
| 2 | import Language.Haskell.TH |
|---|
| 3 | |
|---|
| 4 | defBinOp name op = |
|---|
| 5 | classD (cxt [] (mkName name) [a,b,c] |
|---|
| 6 | [FunDep [a,b] [c], FunDep [b,c] [a], FunDep [a,c] [b]] |
|---|
| 7 | [ sigD (mkName op) $ binOp a b c] |
|---|
| 8 | where |
|---|
| 9 | a = mkName "a" |
|---|
| 10 | b = mkName "b" |
|---|
| 11 | c = mkName "c" |
|---|
| 12 | binOp l m n = arrowT `appT` varT l `appT` (arrowT `appT` varT m `appT` varT n) |
|---|
| 13 | |
|---|
| 14 | |
|---|
| 15 | module Bar where |
|---|
| 16 | import Foo |
|---|
| 17 | import Prelude () |
|---|
| 18 | -- infixl 6 + -- illegal here, because TH not yet evaluated |
|---|
| 19 | $(defBinOp "Add" "+") |
|---|
| 20 | |
|---|
| 21 | module Baz (module Bar) where |
|---|
| 22 | import Bar |
|---|
| 23 | -- infixl 6 + -- illegal here, because its another module! |
|---|