I'm using template Haskell to generate data about a type. For many reasons I need the type to be used to be "normalized". So it shouldn't be a type alias/synonym. I really don't want to disallow using type aliases in the construct since some types that are used can become huge.
So now I have the problem that when a user specifies a type it doesn't match the type I expect. For example if I have this definition:
data MyData a = MyData Int
type Foo = MyData String Int Bool
serializeMyData :: TH.Type -> TH.Q [TH.Dec]
serializeMyData ty = ..
type Foo = MyData Int
And then later in I call this serializeMyData
like this:
$(serializeMyData =<< [t| Foo |] )
Then in the serializeMyData
it will find a ConT Foo
. This is correct since the user has specified the type alias. But is not useable for me.
So my question is how can I resolve type aliases?
Any help is appreciated!
CodePudding user response:
The function resolveTypeSynonyms :: TH.Type -> Q TH.Type
can be found in the library th-abstraction.