kcsongor / generic-lens

Generically derive traversals, lenses, and prisms.
437 stars 53 forks source link

Could an associated type Codomain be added to HasPosition, HasField, AsConstructor? #93

Closed ddssff closed 5 years ago

ddssff commented 5 years ago

I need to obtain the type inferred for a field, can anyone suggest a way to do this? I'm using them to construct types related to the optics returned by field, position, etc. At the moment I'm just constructing a FIeldType type family manually:

data FieldHop = Newtype | FieldPos Nat | FieldName Symbol | ConstrName Symbol

type instance Codomain ('FieldPos 1) Loc = String
type instance Codomain ('FieldPos 2) Loc = String
type instance Codomain ('FieldPos 3) Loc = String
type instance Codomain ('FieldPos 4) Loc = CharPos
type instance Codomain ('FieldPos 5) Loc = CharPos

I envision associated types in the HasFIeld, HasPosition, AsConstructor classes, but I don't see how to implement them.

ddssff commented 5 years ago

I have resolved my confusion.