# Pastebin vXKCVFzi {-# LANGUAGE AllowAmbiguousTypes #-} {-# LANGUAGE RecordWildCards #-} {-# LANGUAGE TypeApplications #-} {-# LANGUAGE TypeFamilies #-} import Control.Lens import Data.Word data Colour = Colour Word8 Word8 Word8 type family QualityType q -- Typelevel tag data ForegroundColour type instance QualityType ForegroundColour = Colour class HasQuality q s where -- could take a proxy argument here if you don't want to use -- AllowAmbiguousTypes and TypeApplications quality :: Lens' s (QualityType q) data SomeRecord = SomeRecord { name :: String, fg :: Colour } instance HasQuality ForegroundColour SomeRecord where quality f r@SomeRecord {..} = f fg <&> \fg' -> r {fg = fg'} -- or use a generated lens whiteout :: HasQuality ForegroundColour a => a -> a whiteout a = a & quality @ForegroundColour .~ Colour 255 255 255