extensible-0.5: Extensible, efficient, optics-friendly data types and effects

Copyright(c) Fumiaki Kinoshita 2018
LicenseBSD3
MaintainerFumiaki Kinoshita <fumiexcel@gmail.com>
Safe HaskellNone
LanguageHaskell2010

Data.Extensible.Field

Contents

Description

Flexible records and variants

Synopsis

Documentation

newtype Field (h :: v -> Type) (kv :: Assoc k v) Source #

A Field h (k ':> v) is h v annotated with the field name k.

Field :: (v -> *) -> Assoc k v -> *

Constructors

Field 

Fields

Instances
Unbox (h (AssocValue x)) => Vector Vector (Field h x) Source # 
Instance details

Defined in Data.Extensible.Field

Methods

basicUnsafeFreeze :: PrimMonad m => Mutable Vector (PrimState m) (Field h x) -> m (Vector (Field h x)) #

basicUnsafeThaw :: PrimMonad m => Vector (Field h x) -> m (Mutable Vector (PrimState m) (Field h x)) #

basicLength :: Vector (Field h x) -> Int #

basicUnsafeSlice :: Int -> Int -> Vector (Field h x) -> Vector (Field h x) #

basicUnsafeIndexM :: Monad m => Vector (Field h x) -> Int -> m (Field h x) #

basicUnsafeCopy :: PrimMonad m => Mutable Vector (PrimState m) (Field h x) -> Vector (Field h x) -> m () #

elemseq :: Vector (Field h x) -> Field h x -> b -> b #

Unbox (h (AssocValue x)) => MVector MVector (Field h x) Source # 
Instance details

Defined in Data.Extensible.Field

Methods

basicLength :: MVector s (Field h x) -> Int #

basicUnsafeSlice :: Int -> Int -> MVector s (Field h x) -> MVector s (Field h x) #

basicOverlaps :: MVector s (Field h x) -> MVector s (Field h x) -> Bool #

basicUnsafeNew :: PrimMonad m => Int -> m (MVector (PrimState m) (Field h x)) #

basicInitialize :: PrimMonad m => MVector (PrimState m) (Field h x) -> m () #

basicUnsafeReplicate :: PrimMonad m => Int -> Field h x -> m (MVector (PrimState m) (Field h x)) #

basicUnsafeRead :: PrimMonad m => MVector (PrimState m) (Field h x) -> Int -> m (Field h x) #

basicUnsafeWrite :: PrimMonad m => MVector (PrimState m) (Field h x) -> Int -> Field h x -> m () #

basicClear :: PrimMonad m => MVector (PrimState m) (Field h x) -> m () #

basicSet :: PrimMonad m => MVector (PrimState m) (Field h x) -> Field h x -> m () #

basicUnsafeCopy :: PrimMonad m => MVector (PrimState m) (Field h x) -> MVector (PrimState m) (Field h x) -> m () #

basicUnsafeMove :: PrimMonad m => MVector (PrimState m) (Field h x) -> MVector (PrimState m) (Field h x) -> m () #

basicUnsafeGrow :: PrimMonad m => MVector (PrimState m) (Field h x) -> Int -> m (MVector (PrimState m) (Field h x)) #

(Bits r, FromBits r (h (AssocValue x))) => FromBits r (Field h x) Source # 
Instance details

Defined in Data.Extensible.Bits

Associated Types

type BitWidth (Field h x) :: Nat Source #

Methods

fromBits :: r -> Field h x Source #

toBits :: Field h x -> r Source #

Wrapper h => Wrapper (Field h :: Assoc k v -> Type) Source # 
Instance details

Defined in Data.Extensible.Field

Associated Types

type Repr (Field h) v :: Type Source #

Methods

_Wrapper :: (Functor f, Profunctor p) => Optic' p f (Field h v0) (Repr (Field h) v0) Source #

wrap :: Repr (Field h) v0 -> Field h v0 Source #

unwrap :: Field h v0 -> Repr (Field h) v0 Source #

Forall (KeyValue KnownSymbol (Instance1 ToJSON h)) xs => ToJSON (Nullable (Field h :: Assoc Symbol v -> Type) :* xs) Source # 
Instance details

Defined in Data.Extensible.Dictionary

Methods

toJSON :: (Nullable (Field h) :* xs) -> Value #

toEncoding :: (Nullable (Field h) :* xs) -> Encoding #

toJSONList :: [Nullable (Field h) :* xs] -> Value #

toEncodingList :: [Nullable (Field h) :* xs] -> Encoding #

Forall (KeyValue KnownSymbol (Instance1 ToJSON h)) xs => ToJSON ((Field h :: Assoc Symbol v -> Type) :* xs) Source # 
Instance details

Defined in Data.Extensible.Dictionary

Methods

toJSON :: (Field h :* xs) -> Value #

toEncoding :: (Field h :* xs) -> Encoding #

toJSONList :: [Field h :* xs] -> Value #

toEncodingList :: [Field h :* xs] -> Encoding #

Forall (KeyValue KnownSymbol (Instance1 FromJSON h)) xs => FromJSON (Nullable (Field h :: Assoc Symbol v -> Type) :* xs) Source # 
Instance details

Defined in Data.Extensible.Dictionary

Forall (KeyValue KnownSymbol (Instance1 FromJSON h)) xs => FromJSON ((Field h :: Assoc Symbol v -> Type) :* xs) Source #

parseJSON Null is called for missing fields.

Instance details

Defined in Data.Extensible.Dictionary

Methods

parseJSON :: Value -> Parser (Field h :* xs) #

parseJSONList :: Value -> Parser [Field h :* xs] #

Forall (KeyValue KnownSymbol (Instance1 FromField h)) xs => FromNamedRecord ((Field h :: Assoc Symbol v -> Type) :* xs) Source # 
Instance details

Defined in Data.Extensible.Dictionary

Forall (KeyValue KnownSymbol (Instance1 ToField h)) xs => ToNamedRecord ((Field h :: Assoc Symbol v -> Type) :* xs) Source # 
Instance details

Defined in Data.Extensible.Dictionary

Methods

toNamedRecord :: (Field h :* xs) -> NamedRecord #

Bounded (h (AssocValue kv)) => Bounded (Field h kv) Source # 
Instance details

Defined in Data.Extensible.Field

Methods

minBound :: Field h kv #

maxBound :: Field h kv #

Enum (h (AssocValue kv)) => Enum (Field h kv) Source # 
Instance details

Defined in Data.Extensible.Field

Methods

succ :: Field h kv -> Field h kv #

pred :: Field h kv -> Field h kv #

toEnum :: Int -> Field h kv #

fromEnum :: Field h kv -> Int #

enumFrom :: Field h kv -> [Field h kv] #

enumFromThen :: Field h kv -> Field h kv -> [Field h kv] #

enumFromTo :: Field h kv -> Field h kv -> [Field h kv] #

enumFromThenTo :: Field h kv -> Field h kv -> Field h kv -> [Field h kv] #

Eq (h (AssocValue kv)) => Eq (Field h kv) Source # 
Instance details

Defined in Data.Extensible.Field

Methods

(==) :: Field h kv -> Field h kv -> Bool #

(/=) :: Field h kv -> Field h kv -> Bool #

Floating (h (AssocValue kv)) => Floating (Field h kv) Source # 
Instance details

Defined in Data.Extensible.Field

Methods

pi :: Field h kv #

exp :: Field h kv -> Field h kv #

log :: Field h kv -> Field h kv #

sqrt :: Field h kv -> Field h kv #

(**) :: Field h kv -> Field h kv -> Field h kv #

logBase :: Field h kv -> Field h kv -> Field h kv #

sin :: Field h kv -> Field h kv #

cos :: Field h kv -> Field h kv #

tan :: Field h kv -> Field h kv #

asin :: Field h kv -> Field h kv #

acos :: Field h kv -> Field h kv #

atan :: Field h kv -> Field h kv #

sinh :: Field h kv -> Field h kv #

cosh :: Field h kv -> Field h kv #

tanh :: Field h kv -> Field h kv #

asinh :: Field h kv -> Field h kv #

acosh :: Field h kv -> Field h kv #

atanh :: Field h kv -> Field h kv #

log1p :: Field h kv -> Field h kv #

expm1 :: Field h kv -> Field h kv #

log1pexp :: Field h kv -> Field h kv #

log1mexp :: Field h kv -> Field h kv #

Fractional (h (AssocValue kv)) => Fractional (Field h kv) Source # 
Instance details

Defined in Data.Extensible.Field

Methods

(/) :: Field h kv -> Field h kv -> Field h kv #

recip :: Field h kv -> Field h kv #

fromRational :: Rational -> Field h kv #

Integral (h (AssocValue kv)) => Integral (Field h kv) Source # 
Instance details

Defined in Data.Extensible.Field

Methods

quot :: Field h kv -> Field h kv -> Field h kv #

rem :: Field h kv -> Field h kv -> Field h kv #

div :: Field h kv -> Field h kv -> Field h kv #

mod :: Field h kv -> Field h kv -> Field h kv #

quotRem :: Field h kv -> Field h kv -> (Field h kv, Field h kv) #

divMod :: Field h kv -> Field h kv -> (Field h kv, Field h kv) #

toInteger :: Field h kv -> Integer #

Num (h (AssocValue kv)) => Num (Field h kv) Source # 
Instance details

Defined in Data.Extensible.Field

Methods

(+) :: Field h kv -> Field h kv -> Field h kv #

(-) :: Field h kv -> Field h kv -> Field h kv #

(*) :: Field h kv -> Field h kv -> Field h kv #

negate :: Field h kv -> Field h kv #

abs :: Field h kv -> Field h kv #

signum :: Field h kv -> Field h kv #

fromInteger :: Integer -> Field h kv #

Ord (h (AssocValue kv)) => Ord (Field h kv) Source # 
Instance details

Defined in Data.Extensible.Field

Methods

compare :: Field h kv -> Field h kv -> Ordering #

(<) :: Field h kv -> Field h kv -> Bool #

(<=) :: Field h kv -> Field h kv -> Bool #

(>) :: Field h kv -> Field h kv -> Bool #

(>=) :: Field h kv -> Field h kv -> Bool #

max :: Field h kv -> Field h kv -> Field h kv #

min :: Field h kv -> Field h kv -> Field h kv #

Real (h (AssocValue kv)) => Real (Field h kv) Source # 
Instance details

Defined in Data.Extensible.Field

Methods

toRational :: Field h kv -> Rational #

RealFloat (h (AssocValue kv)) => RealFloat (Field h kv) Source # 
Instance details

Defined in Data.Extensible.Field

Methods

floatRadix :: Field h kv -> Integer #

floatDigits :: Field h kv -> Int #

floatRange :: Field h kv -> (Int, Int) #

decodeFloat :: Field h kv -> (Integer, Int) #

encodeFloat :: Integer -> Int -> Field h kv #

exponent :: Field h kv -> Int #

significand :: Field h kv -> Field h kv #

scaleFloat :: Int -> Field h kv -> Field h kv #

isNaN :: Field h kv -> Bool #

isInfinite :: Field h kv -> Bool #

isDenormalized :: Field h kv -> Bool #

isNegativeZero :: Field h kv -> Bool #

isIEEE :: Field h kv -> Bool #

atan2 :: Field h kv -> Field h kv -> Field h kv #

RealFrac (h (AssocValue kv)) => RealFrac (Field h kv) Source # 
Instance details

Defined in Data.Extensible.Field

Methods

properFraction :: Integral b => Field h kv -> (b, Field h kv) #

truncate :: Integral b => Field h kv -> b #

round :: Integral b => Field h kv -> b #

ceiling :: Integral b => Field h kv -> b #

floor :: Integral b => Field h kv -> b #

(KnownSymbol k, Wrapper h, Show (Repr h v2)) => Show (Field h (k :> v2)) Source #

Shows in field @= value style instead of the derived one.

Instance details

Defined in Data.Extensible.Field

Methods

showsPrec :: Int -> Field h (k :> v2) -> ShowS #

show :: Field h (k :> v2) -> String #

showList :: [Field h (k :> v2)] -> ShowS #

Generic (Field h kv) Source # 
Instance details

Defined in Data.Extensible.Field

Associated Types

type Rep (Field h kv) :: Type -> Type #

Methods

from :: Field h kv -> Rep (Field h kv) x #

to :: Rep (Field h kv) x -> Field h kv #

Semigroup (h (AssocValue kv)) => Semigroup (Field h kv) Source # 
Instance details

Defined in Data.Extensible.Field

Methods

(<>) :: Field h kv -> Field h kv -> Field h kv #

sconcat :: NonEmpty (Field h kv) -> Field h kv #

stimes :: Integral b => b -> Field h kv -> Field h kv #

Monoid (h (AssocValue kv)) => Monoid (Field h kv) Source # 
Instance details

Defined in Data.Extensible.Field

Methods

mempty :: Field h kv #

mappend :: Field h kv -> Field h kv -> Field h kv #

mconcat :: [Field h kv] -> Field h kv #

Lift (h (AssocValue x)) => Lift (Field h x) Source # 
Instance details

Defined in Data.Extensible.Field

Methods

lift :: Field h x -> Q Exp #

Arbitrary (h (AssocValue kv)) => Arbitrary (Field h kv) Source # 
Instance details

Defined in Data.Extensible.Field

Methods

arbitrary :: Gen (Field h kv) #

shrink :: Field h kv -> [Field h kv] #

Hashable (h (AssocValue kv)) => Hashable (Field h kv) Source # 
Instance details

Defined in Data.Extensible.Field

Methods

hashWithSalt :: Int -> Field h kv -> Int #

hash :: Field h kv -> Int #

ToJSON (h (AssocValue kv)) => ToJSON (Field h kv) Source # 
Instance details

Defined in Data.Extensible.Field

Methods

toJSON :: Field h kv -> Value #

toEncoding :: Field h kv -> Encoding #

toJSONList :: [Field h kv] -> Value #

toEncodingList :: [Field h kv] -> Encoding #

FromJSON (h (AssocValue kv)) => FromJSON (Field h kv) Source # 
Instance details

Defined in Data.Extensible.Field

Methods

parseJSON :: Value -> Parser (Field h kv) #

parseJSONList :: Value -> Parser [Field h kv] #

Storable (h (AssocValue kv)) => Storable (Field h kv) Source # 
Instance details

Defined in Data.Extensible.Field

Methods

sizeOf :: Field h kv -> Int #

alignment :: Field h kv -> Int #

peekElemOff :: Ptr (Field h kv) -> Int -> IO (Field h kv) #

pokeElemOff :: Ptr (Field h kv) -> Int -> Field h kv -> IO () #

peekByteOff :: Ptr b -> Int -> IO (Field h kv) #

pokeByteOff :: Ptr b -> Int -> Field h kv -> IO () #

peek :: Ptr (Field h kv) -> IO (Field h kv) #

poke :: Ptr (Field h kv) -> Field h kv -> IO () #

FromField (h (AssocValue kv)) => FromField (Field h kv) Source # 
Instance details

Defined in Data.Extensible.Field

Methods

parseField :: Field0 -> Parser (Field h kv) #

ToField (h (AssocValue kv)) => ToField (Field h kv) Source # 
Instance details

Defined in Data.Extensible.Field

Methods

toField :: Field h kv -> Field0 #

NFData (h (AssocValue kv)) => NFData (Field h kv) Source # 
Instance details

Defined in Data.Extensible.Field

Methods

rnf :: Field h kv -> () #

(KnownSymbol k, Pretty (h v2)) => Pretty (Field h (k :> v2)) Source # 
Instance details

Defined in Data.Extensible.Field

Methods

pretty :: Field h (k :> v2) -> Doc ann #

prettyList :: [Field h (k :> v2)] -> Doc ann #

Unbox (h (AssocValue x)) => Unbox (Field h x) Source # 
Instance details

Defined in Data.Extensible.Field

data MVector s (Field h x) Source # 
Instance details

Defined in Data.Extensible.Field

data MVector s (Field h x) = MV_Field (MVector s (h (AssocValue x)))
type Repr (Field h :: Assoc k v -> Type) (kv :: Assoc k v) Source # 
Instance details

Defined in Data.Extensible.Field

type Repr (Field h :: Assoc k v -> Type) (kv :: Assoc k v) = Repr h (AssocValue kv)
type Rep (Field h kv) Source # 
Instance details

Defined in Data.Extensible.Field

type Rep (Field h kv) = D1 (MetaData "Field" "Data.Extensible.Field" "extensible-0.5-HtYa3fOZlWC7KXWLoStAWc" True) (C1 (MetaCons "Field" PrefixI True) (S1 (MetaSel (Just "getField") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 (h (AssocValue kv)))))
data Vector (Field h x) Source # 
Instance details

Defined in Data.Extensible.Field

data Vector (Field h x) = V_Field (Vector (h (AssocValue x)))
type BitWidth (Field h x) Source # 
Instance details

Defined in Data.Extensible.Bits

type BitWidth (Field h x) = BitWidth (h (AssocValue x))

(@=) :: Wrapper h => FieldName k -> Repr h v -> Field h (k :> v) infix 1 Source #

Annotate a value by the field name.

foo :: Record '["num" >: Int, "str" >: String]
foo = #num @= 42
  <: #str @= "foo"
  <: nil

(<@=>) :: (Functor f, Wrapper h) => FieldName k -> f (Repr h v) -> Comp f (Field h) (k :> v) infix 1 Source #

Lifted (@=)

foo :: IO (Record '["num" >: Int, "str" >: String])
foo = hsequence
  $ #num <@=> readLn
  <: #str <@=> getLine
  <: nil

(@:>) :: FieldName k -> h v -> Field h (k :> v) infix 1 Source #

Annotate a value by the field name without Wrapper.

(@==) :: FieldName (k :: Symbol) -> v -> Field Identity (k :> v) infix 1 Source #

Kind-monomorphic, unwrapped version of @=

type FieldOptic k = forall kind. forall f p t xs (h :: kind -> Type) (v :: kind). (Extensible f p t, ExtensibleConstr t (Field h) xs (k :> v), Associate k v xs, Labelling k p, Wrapper h) => Optic' p f (t (Field h) xs) (Repr h v) Source #

FieldOptic s is a type of optics that points a field/constructor named s.

The yielding fields can be Lenses for Records and Prisms for Variants.

FieldOptic "foo" = Associate "foo" a xs => Lens' (Record xs) a
FieldOptic "foo" = Associate "foo" a xs => Prism' (Variant xs) a

FieldOptics can be generated using mkField defined in the Data.Extensible.TH module.

type FieldName k = Optic' (LabelPhantom k) Proxy (Inextensible (Field Proxy) '[k :> ()]) () Source #

When you see this type as an argument, it expects a FieldLens. This type is used to resolve the name of the field internally.

liftField :: (g (AssocValue kv) -> h (AssocValue kv)) -> Field g kv -> Field h kv Source #

Lift a function for the content.

liftField2 :: (f (AssocValue kv) -> g (AssocValue kv) -> h (AssocValue kv)) -> Field f kv -> Field g kv -> Field h kv Source #

Lift a function for the content.

Records and variants

type RecordOf h = (:*) (Field h) Source #

The type of records which contain several fields.

RecordOf :: (v -> *) -> [Assoc k v] -> *

type Record = RecordOf Identity Source #

Simple record

emptyRecord :: Record '[] Source #

An empty Record.

type VariantOf h = (:|) (Field h) Source #

The dual of RecordOf

VariantOf :: (v -> *) -> [Assoc k v] -> *

type Variant = VariantOf Identity Source #

Simple variant

Matching

matchWithField :: (forall x. f x -> g x -> r) -> RecordOf f xs -> VariantOf g xs -> r Source #

Select a corresponding field of a variant.

matchField :: RecordOf (Match h r) xs -> VariantOf h xs -> r Source #

Pattern matching on a Variant

Key / value

type family AssocKey (kv :: Assoc k v) :: k where ... Source #

Take the type of the key

Equations

AssocKey (k :> v) = k 

type family AssocValue (kv :: Assoc k v) :: v where ... Source #

Take the type of the value

Equations

AssocValue (k :> v) = v 

class (pk (AssocKey kv), pv (AssocValue kv)) => KeyValue pk pv kv Source #

Combined constraint for Assoc

Instances
(pk k2, pv v2) => KeyValue (pk :: k1 -> Constraint) (pv :: v1 -> Constraint) (k2 :> v2 :: Assoc k1 v1) Source # 
Instance details

Defined in Data.Extensible.Field

proxyAssocKey :: proxy kv -> Proxy (AssocKey kv) Source #

Proxy-level AssocKey. This is useful when using symbolVal.

proxyAssocValue :: proxy kv -> Proxy (AssocValue kv) Source #

Proxy-level AssocValue.

stringAssocKey :: (IsString a, KnownSymbol (AssocKey kv)) => proxy kv -> a Source #

Get a string from a proxy of Assoc Symbol v.

class pk (AssocKey kv) => KeyIs pk kv Source #

Constraint applied to AssocKey

Instances
pk k2 => KeyIs (pk :: k1 -> Constraint) (k2 :> v2 :: Assoc k1 v1) Source # 
Instance details

Defined in Data.Extensible.Field

class pv (AssocValue kv) => ValueIs pv kv Source #

Constraint applied to AssocValue

Instances
pv v2 => ValueIs (pv :: v1 -> Constraint) (k2 :> v2 :: Assoc k1 v1) Source # 
Instance details

Defined in Data.Extensible.Field

Internal

data LabelPhantom s a b Source #

A ghostly type which spells the field name

Instances
Profunctor (LabelPhantom s :: Type -> Type -> Type) Source # 
Instance details

Defined in Data.Extensible.Field

Methods

dimap :: (a -> b) -> (c -> d) -> LabelPhantom s b c -> LabelPhantom s a d #

lmap :: (a -> b) -> LabelPhantom s b c -> LabelPhantom s a c #

rmap :: (b -> c) -> LabelPhantom s a b -> LabelPhantom s a c #

(#.) :: Coercible c b => q b c -> LabelPhantom s a b -> LabelPhantom s a c #

(.#) :: Coercible b a => LabelPhantom s b c -> q a b -> LabelPhantom s a c #

type family Labelling s p :: Constraint where ... Source #

Signifies a field name internally

Equations

Labelling s (LabelPhantom t) = s ~ t 
Labelling s p = () 

data Inextensible (h :: k -> Type) (xs :: [k]) Source #

The trivial inextensible data type

Instances
(Functor f, Profunctor p) => Extensible f p (Inextensible :: (k -> Type) -> [k] -> Type) Source # 
Instance details

Defined in Data.Extensible.Field

Associated Types

type ExtensibleConstr Inextensible h xs x :: Constraint Source #

Methods

pieceAt :: ExtensibleConstr Inextensible h xs x => Membership xs x -> Optic' p f (Inextensible h xs) (h x) Source #

type ExtensibleConstr (Inextensible :: (k -> Type) -> [k] -> Type) (h :: k -> Type) (xs :: [k]) (x :: k) Source # 
Instance details

Defined in Data.Extensible.Field

type ExtensibleConstr (Inextensible :: (k -> Type) -> [k] -> Type) (h :: k -> Type) (xs :: [k]) (x :: k) = ()