kcsongor / generic-lens

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

Consider adding HasConstraints back #109

Open kcsongor opened 4 years ago

kcsongor commented 4 years ago

I removed this feature from 2.0.0.0 because the motivation for it was quite weak and I wasn't happy with the interface. However, if we can find a more consistent story and some motivating examples, it would be great to add it back.

AriFordsham commented 2 years ago

I found HasConstraints insufficiently general.

Example: a datatype for the UCS-2 encoding (https://en.wikipedia.org/wiki/Universal_Coded_Character_Set)

data UCS2
  = Nil
  | Cons
  { ucs2First :: Word8
  , ucs2Second :: Word8
  , ucs2Tail :: UCS2
  }

I cannot use HasConstraints (or any generic-lens combinator, if I were to omit the field labels) to traverse just the ucs2First field.

I would love to see what a sufficiently general solution would look like.