extensible-0.6: 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 (TargetOf 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 (TargetOf 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 (TargetOf 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 (KeyTargetAre KnownSymbol (Instance1 ToJSON h)) xs => ToJSON (xs :& Nullable (Field h :: Assoc Symbol v -> Type)) Source # 
Instance details

Defined in Data.Extensible.Dictionary

Methods

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

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

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

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

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

Defined in Data.Extensible.Dictionary

Methods

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

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

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

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

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

Defined in Data.Extensible.Dictionary

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

parseJSON Null is called for missing fields.

Instance details

Defined in Data.Extensible.Dictionary

Methods

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

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

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

Defined in Data.Extensible.Dictionary

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

Defined in Data.Extensible.Dictionary

Methods

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

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

Defined in Data.Extensible.Field

Methods

minBound :: Field h kv #

maxBound :: Field h kv #

Enum (h (TargetOf 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 (TargetOf 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 (TargetOf 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 (TargetOf 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 (TargetOf 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 (TargetOf 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 (TargetOf 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 (TargetOf kv)) => Real (Field h kv) Source # 
Instance details

Defined in Data.Extensible.Field

Methods

toRational :: Field h kv -> Rational #

RealFloat (h (TargetOf 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 (TargetOf 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 (TargetOf 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 (TargetOf 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 (TargetOf x)) => Lift (Field h x) Source # 
Instance details

Defined in Data.Extensible.Field

Methods

lift :: Field h x -> Q Exp #

Arbitrary (h (TargetOf 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 (TargetOf 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 (TargetOf 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 (TargetOf 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 (TargetOf 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 (TargetOf kv)) => FromField (Field h kv) Source # 
Instance details

Defined in Data.Extensible.Field

Methods

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

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

Defined in Data.Extensible.Field

Methods

toField :: Field h kv -> Field0 #

NFData (h (TargetOf 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 (TargetOf x)) => Unbox (Field h x) Source # 
Instance details

Defined in Data.Extensible.Field

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

Defined in Data.Extensible.Field

newtype MVector s (Field h x) = MV_Field (MVector s (h (TargetOf 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 (TargetOf 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.6-A4iOCEmxehHHc7U2kkvBLL" True) (C1 (MetaCons "Field" PrefixI True) (S1 (MetaSel (Just "getField") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 (h (TargetOf kv)))))
newtype Vector (Field h x) Source # 
Instance details

Defined in Data.Extensible.Field

newtype Vector (Field h x) = V_Field (Vector (h (TargetOf x)))
type BitWidth (Field h x) Source # 
Instance details

Defined in Data.Extensible.Bits

type BitWidth (Field h x) = BitWidth (h (TargetOf 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 xs (Field h) (k :> v), Lookup xs k v, Labelling k p, Wrapper h) => Optic' p f (t xs (Field h)) (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 '[k :> ()] (Field Proxy)) () 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 (TargetOf kv) -> h (TargetOf kv)) -> Field g kv -> Field h kv Source #

Lift a function for the content.

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

Lift a function for the content.

Records and variants

type RecordOf h xs = xs :& Field h Source #

The type of records which contain several fields.

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

type Record xs = RecordOf Identity xs Source #

Simple record

emptyRecord :: Record '[] Source #

An empty Record.

type VariantOf h xs = xs :/ Field h Source #

The dual of RecordOf

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

type Variant xs = VariantOf Identity xs 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 KeyOf (kv :: Assoc k v) :: k where ... #

Take the type of the key

Equations

KeyOf (k2 :> v2 :: Assoc k1 v1) = k2 

proxyKeyOf :: proxy kv -> Proxy (KeyOf kv) #

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

stringKeyOf :: (IsString a, KnownSymbol (KeyOf kv)) => proxy kv -> a #

Get a string from a proxy of Assoc Symbol v.

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

Take the type of the value

Equations

TargetOf (k2 :> v2 :: Assoc k1 v1) = v2 

proxyTargetOf :: proxy kv -> Proxy (TargetOf kv) #

Proxy-level TargetOf.

class pk (KeyOf kv) => KeyIs (pk :: k -> Constraint) (kv :: Assoc k v) #

Constraint applied to KeyOf

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

Defined in Type.Membership

class pv (TargetOf kv) => TargetIs (pv :: k1 -> Constraint) (kv :: Assoc k k1) #

Constraint applied to TargetOf

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

Defined in Type.Membership

class (pk (KeyOf kv), pv (TargetOf kv)) => KeyTargetAre (pk :: k -> Constraint) (pv :: k1 -> Constraint) (kv :: Assoc k k1) #

Combined constraint for Assoc

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

Defined in Type.Membership

deprecated

type AssocKey kv = KeyOf kv Source #

Deprecated: Use KeyOf instead

type AssocValue kv = TargetOf kv Source #

Deprecated: Use TargetOf instead

type ValueIs = TargetIs Source #

Deprecated: Use TargetIs instead

type KeyValue = KeyTargetAre Source #

Deprecated: Use KeyTargetAre instead

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

Deprecated: Use proxyKeyOf instead

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

Deprecated: Use stringKeyOf instead

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

Deprecated: Use proxyTargetOf instead

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 (xs :: [k]) (h :: k -> Type) Source #

The trivial inextensible data type

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

Defined in Data.Extensible.Field

Associated Types

type ExtensibleConstr Inextensible xs h x :: Constraint Source #

Methods

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

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

Defined in Data.Extensible.Field

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