Search code examples
haskelltemplate-haskellhaskell-lens

Is this expected behavior of Template Haskell?


Can anyone tell why this code doesn't compile

data A = A {
  _b  :: B
}
makeLenses ''A

type B = String

with message

Not in scope: type constructor or class B

and this does:

type B = String

data A = A {
  _b  :: B
}
makeLenses ''A

Without makeLenses everything compiles fine.

Why can't I have type synonim declaration after makeLenses?


Solution

  • Only the definitions before the template haskell call are accessible in the scope.

    See this previous question on the same topic: Haskell: Template Haskell and the scope.