danidiaz / dep-t

Dependency injection for records-of-functions.
http://hackage.haskell.org/package/dep-t
BSD 3-Clause "New" or "Revised" License
8 stars 2 forks source link

Add FirstFieldWithThatType newtype helper for deriving Has #10

Closed danidiaz closed 3 years ago

danidiaz commented 3 years ago

Having to depend on field names for wiring components is tedious. If there aren't two different components of the same type in the environment, it's better to "autowire" them from the type information alone. We could dispense with field names altogeher!

So perhaps we could add a FirstFieldWithThatType helper (to be used with Generics and DerivingVia) that generated Has instances by searching matching types in the environment.

Instances would probably be hideously slow to compile for large environment records, but for smallish ones it could cut down the boilerplate.

danidiaz commented 3 years ago

Added in 3a6bb85d34b63ac3d6b4c464f5a808d12eb8317b.