Copyright | (C) Koz Ross 2019 |
---|---|
License | GPL version 3.0 or later |
Stability | Experimental |
Portability | GHC only |
Safe Haskell | Trustworthy |
Language | Haskell2010 |
Knowing that a type a
is an instance of Finitary
gives us the knowledge
that there is an isomorphism between a
and Finite n
for some KnownNat
n
. This gives us a lot of information, which we can exploit to automagically
derive a range of type class instances.
Finiteness
is a newtype
wrapper providing this functionality, while
're-exporting' as many type class instances of the underlying type as
possible. It is designed for use with DerivingVia
- an example of use:
{-# LANGUAGE DerivingVia #-} {-# LANGUAGE DeriveAnyClass #-} {-# LANGUAGE DeriveGeneric #-} import GHC.Generics import Data.Finitary import Data.Finitary.Finiteness import Data.Word import Control.DeepSeq import Data.Hashable import Data.Binary data Foo = Bar | Baz (Word8, Word8) | Quux Word16 deriving (Eq, Generic, Finitary) deriving (Ord, Bounded, NFData, Hashable, Binary) via (Finiteness Foo)
Currently, the following type class instances can be derived in this manner:
Ord
Bounded
NFData
Hashable
Binary
Additionally, Finiteness
'forwards' definitions of the following type
classes:
Eq
Show
Read
Typeable
Data
Semigroup
Monoid
Synopsis
- newtype Finiteness a = Finiteness {
- unFiniteness :: a
Documentation
newtype Finiteness a Source #
Essentially Identity
with a different name. Named this way due to the
wordplay you get from use with DerivingVia
.
Finiteness | |
|
Instances
Functor Finiteness Source # | |
Defined in Data.Finitary.Finiteness fmap :: (a -> b) -> Finiteness a -> Finiteness b # (<$) :: a -> Finiteness b -> Finiteness a # | |
(Finitary a, 1 <= Cardinality a) => Bounded (Finiteness a) Source # | Since any inhabited |
Defined in Data.Finitary.Finiteness minBound :: Finiteness a maxBound :: Finiteness a | |
Eq a => Eq (Finiteness a) Source # | |
Defined in Data.Finitary.Finiteness (==) :: Finiteness a -> Finiteness a -> Bool (/=) :: Finiteness a -> Finiteness a -> Bool | |
Data a => Data (Finiteness a) Source # | |
Defined in Data.Finitary.Finiteness gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> Finiteness a -> c (Finiteness a) gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c (Finiteness a) toConstr :: Finiteness a -> Constr dataTypeOf :: Finiteness a -> DataType dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c (Finiteness a)) dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (Finiteness a)) gmapT :: (forall b. Data b => b -> b) -> Finiteness a -> Finiteness a gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Finiteness a -> r gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Finiteness a -> r gmapQ :: (forall d. Data d => d -> u) -> Finiteness a -> [u] gmapQi :: Int -> (forall d. Data d => d -> u) -> Finiteness a -> u gmapM :: Monad m => (forall d. Data d => d -> m d) -> Finiteness a -> m (Finiteness a) gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> Finiteness a -> m (Finiteness a) gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> Finiteness a -> m (Finiteness a) | |
Finitary a => Ord (Finiteness a) Source # |
|
Defined in Data.Finitary.Finiteness compare :: Finiteness a -> Finiteness a -> Ordering (<) :: Finiteness a -> Finiteness a -> Bool (<=) :: Finiteness a -> Finiteness a -> Bool (>) :: Finiteness a -> Finiteness a -> Bool (>=) :: Finiteness a -> Finiteness a -> Bool max :: Finiteness a -> Finiteness a -> Finiteness a min :: Finiteness a -> Finiteness a -> Finiteness a | |
Read a => Read (Finiteness a) Source # | |
Defined in Data.Finitary.Finiteness readsPrec :: Int -> ReadS (Finiteness a) readList :: ReadS [Finiteness a] readPrec :: ReadPrec (Finiteness a) readListPrec :: ReadPrec [Finiteness a] | |
Show a => Show (Finiteness a) Source # | |
Defined in Data.Finitary.Finiteness showsPrec :: Int -> Finiteness a -> ShowS show :: Finiteness a -> String showList :: [Finiteness a] -> ShowS | |
Semigroup a => Semigroup (Finiteness a) Source # | |
Defined in Data.Finitary.Finiteness (<>) :: Finiteness a -> Finiteness a -> Finiteness a sconcat :: NonEmpty (Finiteness a) -> Finiteness a stimes :: Integral b => b -> Finiteness a -> Finiteness a | |
Monoid a => Monoid (Finiteness a) Source # | |
Defined in Data.Finitary.Finiteness mempty :: Finiteness a mappend :: Finiteness a -> Finiteness a -> Finiteness a mconcat :: [Finiteness a] -> Finiteness a | |
Finitary a => Finitary (Finiteness a) Source # |
|
Defined in Data.Finitary.Finiteness type Cardinality (Finiteness a) :: Nat # fromFinite :: Finite (Cardinality (Finiteness a)) -> Finiteness a # toFinite :: Finiteness a -> Finite (Cardinality (Finiteness a)) # start :: Finiteness a # end :: Finiteness a # previous :: Finiteness a -> Maybe (Finiteness a) # next :: Finiteness a -> Maybe (Finiteness a) # | |
Finitary a => Hashable (Finiteness a) Source # | Any |
Defined in Data.Finitary.Finiteness hashWithSalt :: Int -> Finiteness a -> Int # hash :: Finiteness a -> Int # | |
Finitary a => NFData (Finiteness a) Source # | We can force evaluation of a |
Defined in Data.Finitary.Finiteness rnf :: Finiteness a -> () | |
Finitary a => Binary (Finiteness a) Source # | Any |
Defined in Data.Finitary.Finiteness | |
type Cardinality (Finiteness a) Source # | |
Defined in Data.Finitary.Finiteness |