Idiomatic way to exchange definitions of lens fields among modules

If I have two modules that use Control.Lens.TH ' makeFields to generate fields from a record, and the record in each of the different modules has the same field name, which is the best way to ensure that these two modules use the same definition the name lens and the HasName class, without having one of the modules, depends on the other?

I am currently using another module called SharedFields with one record with each field that you want to share, and then import the SharedFields module into everything that the TH fields require, but this is inconvenient and error free.

 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 
+6
source share

Source: https://habr.com/ru/post/976119/


All Articles