derivingvia-extras-0.1.0.0: DerivingVia extras - Miscellaneous /via/ types.
Safe HaskellSafe-Inferred
LanguageHaskell98

Deriving.On

Synopsis
  • newtype On a field = On a

Documentation

newtype On a field Source #

With DerivingVia: to derive non-structural instances. Specifies what field to base instances on.

The type On User "userID" is compared and evaluated based only on the "userID" record field. This uses HasField from GHC.Records to project the relevant component.

{--}
{--}
{--}

import Deriving.On
import Data.Hashable

data User = User
  { name   :: String
  , age    :: Int
  , userID :: Integer
  }
  deriving (Eq, Ord, Hashable)
  via User On "userID"
>> alice = User Alice 50 0xDEADBEAF
>> bob   = User Bob   20 0xDEADBEAF
>>
>> alice == bob
True
>> alice <= bob
True
>> hash alice == hash bob
True

Constructors

On a 

Instances

Instances details
(HasField field a b, Eq b) => Eq (On a field) Source # 
Instance details

Defined in Deriving.On

Methods

(==) :: On a field -> On a field -> Bool #

(/=) :: On a field -> On a field -> Bool #

(HasField field a b, Ord b) => Ord (On a field) Source # 
Instance details

Defined in Deriving.On

Methods

compare :: On a field -> On a field -> Ordering #

(<) :: On a field -> On a field -> Bool #

(<=) :: On a field -> On a field -> Bool #

(>) :: On a field -> On a field -> Bool #

(>=) :: On a field -> On a field -> Bool #

max :: On a field -> On a field -> On a field #

min :: On a field -> On a field -> On a field #

(HasField field a b, Hashable b) => Hashable (On a field) Source # 
Instance details

Defined in Deriving.On

Methods

hashWithSalt :: Int -> On a field -> Int #

hash :: On a field -> Int #