over quantity Polymorph $ increment Quantity q2 = over quantities . Maybe newtype Quantity = Quantity Integer deriving (Eq, Num, Ord, Random, Show) data Fighter = Team Player | Lone Wolf | Polymorph deriving (Eq, Ord, Show) data World = World deriving (Show) $(make Lenses ''World) at Fighter i = at i . Put there a minimal code example that illustrates why you think you need Get rid of direct enumeration of q1 and so on, with usage of quantity Polymorph and others in them. Random data Quantity = Quantity Integer deriving (Show) instance Random Quantity where random R (Quantity lo, Quantity hi) g = let rand = random R (lo, hi) g (r, g1) = rand in (Quantity r, g1) random g = let rand = random g (r, g1) = rand in (Quantity r, g1) instance Eq Quantity where (==) (Quantity q1) (Quantity q2) = q1 == q2 instance Ord Quantity where ( Just $ q3 w where q1 = over quantities . Since there have been too many improvements to your code it's better to create a new question for that.At its simplest, a lens is a value representing maps between a complex type and one of its constituents.This map works both ways—we can get or "access" the constituent and set or "mutate" it.However, using the magic of type classes we can hack up something approaching a solution.Let’s desugar the records as before, but instead of those name functions add this lot: All we have done here is used the happy (and not entirely accidental) fact that the ‘name’ field is of type String in both records to create a type class with instances to let us extract it from both record types.
Actually, we could use this hack to establish something like a subtype relationship on records, since any record with at least the fields of another could implement all of its field type classes (like the Name Field type class, in this example).Both Haskell and Purescript have a notion of "records," which are types that have a fixed set of named fields.The two languages treat them very differently, each with some advantages and disadvantages..action_button.action_button:active.action_button:hover.action_button:focus,.action_button:hover.action_button:focus .count,.action_button:hover .count.action_button:focus .count:before,.action_button:hover .count:bullet. Error Banner.fade_out.modal_overlay.modal_overlay .modal_wrapper.modal_overlay [email protected](max-width:630px)@media(max-width:630px).modal_overlay .modal_fixed_close.modal_overlay .modal_fixed_close:before.modal_overlay .modal_fixed_close:before.modal_overlay .modal_fixed_close:before.modal_overlay .modal_fixed_close:hover:before.