If I have two modules that both use Control.Lens.TH
' makeFields
to generate fields from a record, and a record in each of the different modules has the same field name, what's the best way of ensuring that the two modules are using the same definition of the name
lens and the HasName
class without having one of the modules depend on the other?
At the moment, I'm using another module named SharedFields
with a single record with every field that needs shared, and then importing the SharedFields
module in anything else that needs TH fields generated – but this is awkward and error-prone.
module First where
import Control.Lens
data First = First { firstName :: Bool }
deriving (Read, Show, Eq)
makeFields ''First
module Second where
import Control.Lens
data Second = Second { secondName :: () }
deriving (Read, Show, Eq)
makeFields ''Second
module Third (name) where
import First
import Second