Skip to content

Icelandjack/derivingvia-extras

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

derivingvia-extras

Miscellaneous via types, for use with DerivingVia.

On

The type On T "field" derives non-structural instances for T by comparing an evaluting it only at the record field "field".

{-# Language DataKinds     #-}
{-# Language DerivingVia   #-}
{-# Language TypeOperators #-}

import Deriving.On
import Data.Hashable

data User = User
  { name   :: String
  , age    :: Int
  , userID :: Integer
  }
  deriving (Eq, Ord, Hashable)
  via User `On` "userID"

such that all other fields are ignored

>> alice = User "Alice" 50 0xDEADBEAF
>> bob   = User "Bob"   20 0xDEADBEAF
>>
>> alice == bob
True
>> alice <= bob
True
>> hash alice == hash bob
True

About

Miscellaneous via types.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published