ruin-0.1.0.1: Pliable records

Safe HaskellNone
LanguageHaskell2010

Data.Ruin.R

Contents

Description

Anonymous records.

Synopsis

Data kind for fields declarations

data FD Source #

An abstract data kind for the field declarations that determine an anonymous record type. The user can only build this type using the handful of type families exported by this module.

These families ensure that GHC's type equality relation ~ ignores the order in which fields with different names are added to/removed from the declarations.

Constructors

type (:::) s ty = ('(s, ty) :: (Symbol, *)) infix 0 Source #

A field declaration.

type family InsertFD (s :: Symbol) (ty :: *) (fd :: FD) :: FD where ... Source #

Equations

InsertFD s ty (MkFD ds) = MkFD (Insert1 s ty ds) 

type family NilFD :: FD where ... Source #

Equations

NilFD = MkFD '[] 

type family MkFD (ds :: [(Symbol, *)]) :: FD where ... Source #

Create a fields declaration from a list of individual field declarations. For example,MkFD '["x" ::: Bool,"y" ::: Maybe Int]) :: FD.

Equations

MkFD '[] = NilFD 
MkFD (d ': ds) = InsertFD (Fst d) (Snd d) (MkFD ds) 

type family PlusFD (fd1 :: FD) (fd2 :: FD) :: FD where ... Source #

Each field that is in both declaration lists will have an undefined type.

  *Data.Ruin.R> :t oneR #x () `plusR` (oneR #x () `plusR` oneR #y ())
  oneR #x () `plusR` (oneR #x () `plusR` oneR #y ())
    :: R ('MkFD '[ '("x", (TypeError ...)), '("y", ())) ])

Equations

PlusFD (MkFD ds1) (MkFD ds2) = MkFD (Plus1 (MkFD ds1) (MkFD ds2) ds1 ds2) 

Operations

type family DeleteFD (s :: Symbol) (fd :: FD) :: FD where ... Source #

Equations

DeleteFD s (MkFD ds) = MkFD (Delete1 s ds) 

type family LookupFD (s :: Symbol) (fd :: FD) :: * where ... Source #

Equations

LookupFD s (MkFD ds) = FinalLookup s (MkFD ds) (Lookup1 s ds) 

type family LMergeFD (fd1 :: FD) (fd2 :: FD) :: FD where ... Source #

A left-biased version of PlusFD; instead of undefined types, shared fields will keep their type from the left declarations.

Equations

LMergeFD (MkFD ds1) (MkFD ds2) = MkFD (LMerge1 ds1 ds2) 

type family HomogenizeFD (c :: *) (fd :: FD) :: FD where ... Source #

Equations

HomogenizeFD c (MkFD ds) = MkFD (MapSecondConst c ds) 

Constraints

type family FDAbsent (s :: Symbol) (fd :: FD) :: Constraint where ... Source #

Equations

FDAbsent s (MkFD ds) = FDAbsent1 s (MkFD ds) (Lookup1 s ds) 

type family FDFoldable (fun :: *) (fd1 :: FD) (fd2 :: FD) (m :: *) where ... Source #

Equations

FDFoldable fun fd1 fd2 m = (FDPure fun fd1, FDSplat fd1 fd2 (HomogenizeFD m fd2), FDHomogenous m (HomogenizeFD m fd2), Monoid m, UnifyShape (R fd1) (R fd2), UnifyShape (R fd2) (R (HomogenizeFD m fd2))) 

type family FDFoldable2 (fun :: *) (fd1 :: FD) (fd2 :: FD) (fd3 :: FD) (m :: *) where ... Source #

Equations

FDFoldable2 fun fd1 fd2 fd3 m = (FDPure fun fd1, FDSplat fd1 fd2 fd3, FDSplat fd3 fd2 (HomogenizeFD m fd2), FDHomogenous m (HomogenizeFD m fd2), Monoid m, UnifyShape (R fd1) (R fd2), UnifyShape (R fd2) (R fd3), UnifyShape (R fd2) (R (HomogenizeFD m fd2))) 

type family FDHomogenous (a :: *) (fd :: FD) :: Constraint where ... Source #

Every field in fd has the same type, a.

Equations

FDHomogenous a fd = (FDHomogenous1 a (FieldsFD fd), Hoid MkFD fd) 

type family FDPure (a :: *) (fd :: FD) :: Constraint where ... Source #

The type and value of a determine the type and value of every field in fd.

Equations

FDPure a fd = (FDPure0 a fd, Hoid MkFD fd) 

type family FDSplat (fd1 :: FD) (fd2 :: FD) (fd3 :: FD) :: Constraint where ... Source #

Each field in fd1 is a function from the same field in fd2 to the same field in fd3.

Equations

FDSplat (MkFD ds1) (MkFD ds2) (MkFD ds3) = FDSplat1 ds1 ds2 ds3 

type family FDSplatA (i :: * -> *) (fd1 :: FD) (fd2 :: FD) (fd3 :: FD) :: Constraint where ... Source #

Each field in fd1 is a function from the same field in fd2 to an i-structure of the same field in fd3.

Equations

FDSplatA i (MkFD ds1) (MkFD ds2) (MkFD ds3) = FDSplatA1 i ds1 ds2 ds3 

fdIdentities :: forall s fd a. '(LookupFD s (InsertFD s a fd), InsertFD s (LookupFD s fd) fd, DeleteFD s (DeleteFD s fd), InsertFD s a (DeleteFD s fd), Lookup1 s (FieldsFD (DeleteFD s fd)), MkFD (FirstHalf (FieldsFD fd)) `PlusFD` MkFD (SecondHalf (FieldsFD fd))) :~: '(a, fd, DeleteFD s fd, InsertFD s a fd, Nothing, fd) Source #

This type equality provides a "proof by fiat" of some obvious identities involving the fields declarations combinators.

You typically won't need to use this.

Anonymous records

data R fd Source #

A record with fields declarations fd :: FD is a product type with one factor per declared field.

Instances

ClosedHas s (R fd) => Has s (R fd) Source # 

Associated Types

type FieldType (s :: Symbol) (R fd) :: * Source #

Methods

extricate1 :: Label s -> R fd -> Eval (FieldType s (R fd)) Source #

KnownSymbol s => HasCase s (R fd) Source # 

Associated Types

type FieldTypeCase (s :: Symbol) (R fd) :: * Source #

Methods

extricate1Case :: Label s -> R fd -> Eval (FieldType s (R fd)) Source #

FDFoldable2 REq ex1 fd ex3 All => Eq (R fd) Source # 

Methods

(==) :: R fd -> R fd -> Bool #

(/=) :: R fd -> R fd -> Bool #

(Eq (R fd), FDFoldable2 RCompare ex1 fd ex3 Ordering) => Ord (R fd) Source # 

Methods

compare :: R fd -> R fd -> Ordering #

(<) :: R fd -> R fd -> Bool #

(<=) :: R fd -> R fd -> Bool #

(>) :: R fd -> R fd -> Bool #

(>=) :: R fd -> R fd -> Bool #

max :: R fd -> R fd -> R fd #

min :: R fd -> R fd -> R fd #

FDFoldable RShowField ex1 fd [String] => Show (R fd) Source # 

Methods

showsPrec :: Int -> R fd -> ShowS #

show :: R fd -> String #

showList :: [R fd] -> ShowS #

(Hoid FD ([(Symbol, *)] -> FD) MkFD fd, GenericDs (FieldsFD fd)) => Generic (R fd) Source #

Beware: these conversions are inefficient and very unlikely to be simplified away.

Associated Types

type Rep (R fd) :: * -> * #

Methods

from :: R fd -> Rep (R fd) x #

to :: Rep (R fd) x -> R fd #

FDFoldable RLiftField ex1 fd [ExpQ] => Lift (R fd) Source # 

Methods

lift :: R fd -> Q Exp #

(KnownFD fd, Hoid FD ([(Symbol, *)] -> FD) MkFD fd) => Build (R fd) Source # 

Associated Types

type Fields (R fd) :: [(Symbol, *)] Source #

type Shape (R fd) o :: Constraint Source #

Methods

build :: (Applicative i, GivesThese (Fields (R fd)) i rc) => rc -> Compose * * Eval i (R fd) Source #

buildNonStrict :: GivesThese (Fields (R fd)) Identity rc => rc -> R fd Source #

type FieldType s (R fd) Source # 
type FieldType s (R fd) = FieldTypeCase s (R fd)
type FieldTypeCase s (R fd) Source # 
type FieldTypeCase s (R fd) = LookupFD s fd
type Rep (R fd) Source # 
type Rep (R fd)
type Fields (R fd) Source # 
type Fields (R fd)
type Shape (R fd) o Source # 
type Shape (R fd) o

type Rcrd ds = R (MkFD ds) Source #

A convenient alias.

Constructors

oneR :: KnownSymbol s => Label s -> a -> R (InsertFD s a NilFD) Source #

plusR :: R fd1 -> R fd2 -> R (PlusFD fd1 fd2) Source #

Each field that is in both records will have an undefined type.

Operations

addR :: (KnownSymbol s, FDAbsent s fd) => Label s -> a -> R fd -> R (InsertFD s a fd) Source #

A version of insertR that requires that the field is not already in the record. setR is the opposite.

adjustR :: (KnownSymbol s, fd1 ~ InsertFD s a fd2, fd2 ~ InsertFD s b fd1) => Label s -> (a -> b) -> R fd1 -> R fd2 Source #

deleteR :: KnownSymbol s => Label s -> R fd -> R (DeleteFD s fd) Source #

extricate1R :: KnownSymbol s => Label s -> R fd -> Eval (LookupFD s fd) Source #

When forced, this Eval computation extricates the value of the field from the rest of the record without forcing the value of the field itself. See extricate1 for further motivation.

getR :: KnownSymbol s => Label s -> R fd -> LookupFD s fd Source #

insertR :: KnownSymbol s => Label s -> a -> R fd -> R (InsertFD s a fd) Source #

Add a field to a record, or overwrite it if it's already present. See addR and setR.

lensR :: (KnownSymbol s, fd1 ~ InsertFD s a fd2, fd2 ~ InsertFD s b fd1, Functor f) => Label s -> (a -> f b) -> R fd1 -> f (R fd2) Source #

The "lensR/adjustR" RULE rewrites lensR to the more efficient adjustR whenever the lens's functor is Identity.

Most notably, Control.Lens.over uses Identity.

lmergeR :: R fd1 -> R fd2 -> R (LMergeFD fd1 fd2) Source #

Left-biased.

setR :: forall s fd. KnownSymbol s => Label s -> LookupFD s fd -> R fd -> R fd Source #

A version of insertR that requires that the field is already in the record. addR is the opposite.

Fieldwise operations

class FPure a s b where Source #

How to create a field s of type b from a value of a.

Minimal complete definition

fpure

Methods

fpure :: a -> b Source #

Instances

(Ord a, (~) * b (a -> a -> Ordering)) => FPure RCompare s b Source # 

Methods

fpure :: RCompare -> b Source #

(Eq a, (~) * b (a -> a -> All)) => FPure REq s b Source # 

Methods

fpure :: REq -> b Source #

(KnownSymbol s, Show a, (~) * b (a -> [String])) => FPure RShowField s b Source # 

Methods

fpure :: RShowField -> b Source #

(~) * b (dom -> cod) => FPure (dom -> cod) s b Source #

Same as rmonopure.

Methods

fpure :: (dom -> cod) -> b Source #

data RCompare Source #

Constructors

MkRCompare 

Instances

(Ord a, (~) * b (a -> a -> Ordering)) => FPure RCompare s b Source # 

Methods

fpure :: RCompare -> b Source #

data REq Source #

Constructors

MkREq 

Instances

(Eq a, (~) * b (a -> a -> All)) => FPure REq s b Source # 

Methods

fpure :: REq -> b Source #

data RShowField Source #

For example:

  *Data.Ruin.R> mapM_ putStrLn $ rfoldMapR MkRShowField $ oneR #x "x" `plusR` oneR #y ()
  x = "x"
  y = ()

Constructors

MkRShowField 

Instances

(KnownSymbol s, Show a, (~) * b (a -> [String])) => FPure RShowField s b Source # 

Methods

fpure :: RShowField -> b Source #

rfoldR :: (Monoid m, FDHomogenous m fd) => R fd -> m Source #

Beware: the order in which the fields are combined is undefined, so the Monoid ought to be commutative.

rfoldMapR :: forall fd1 fd2 fun m. FDFoldable fun fd1 fd2 m => fun -> R fd2 -> m Source #

rfoldMap2R :: forall fd1 fd2 fd3 fun m. FDFoldable2 fun fd1 fd2 fd3 m => fun -> R fd2 -> R fd2 -> m Source #

rlabelR :: FDPure RLabel fd => R fd Source #

A specialized rlabel for R.

rmapR :: forall fd1 fd2 fd3 fun. (FDPure fun fd1, FDSplat fd1 fd2 fd3, UnifyShape (R fd1) (R fd2), UnifyShape (R fd2) (R fd3)) => fun -> R fd2 -> R fd3 infixl 4 Source #

A specialized rmap for R.

rmapAR :: forall fun fd1 fd2 fd3 i. (Applicative i, FDPure fun fd1, FDSplatA i fd1 fd2 fd3, UnifyShape (R fd1) (R fd2), UnifyShape (R fd2) (R fd3)) => fun -> R fd2 -> i (R fd3) infixl 4 Source #

A specialized rmapA for R.

rmappendR :: FDPure RMAppendR fd => R fd Source #

A specialized rmappend for R.

rmemptyR :: FDPure RMEmpty fd => R fd Source #

A specialized rmempty for R.

rpureR :: FDPure a fd => a -> R fd Source #

A specialized rpure for R.

rpolypureR :: FDPure a fd => a -> R fd Source #

A specialized rpolypure for R.

rsappendR :: FDPure RSAppendR fd => R fd Source #

A specialized rsappend for R.

rsplatR :: (FDSplat fd1 fd2 fd3, UnifyShape (R fd1) (R fd2), UnifyShape (R fd2) (R fd3)) => R fd1 -> R fd2 -> R fd3 infixl 4 Source #

A specialized rsplat for R.

rsplatAR :: (Applicative i, FDSplatA i fd1 fd2 fd3, UnifyShape (R fd1) (R fd2), UnifyShape (R fd2) (R fd3)) => R fd1 -> R fd2 -> i (R fd3) infixl 4 Source #

A specialized rsplatA for R.

Monomorphic specializations

monoadjustR :: forall s fd. KnownSymbol s => Label s -> (LookupFD s fd -> LookupFD s fd) -> R fd -> R fd Source #

lens'R :: forall s fd f. (KnownSymbol s, Functor f) => Label s -> (LookupFD s fd -> f (LookupFD s fd)) -> R fd -> f (R fd) Source #

rmonopureR :: FDPure (RMonoPure a) fd => a -> R fd Source #

A specialized rmonopure for R.

Field labels

data Label s Source #

Use -XOverloadedLabels to create labels. For example, #x :: Label "x".

Or use mkLabel.

Instances

(~) Symbol s1 s2 => IsLabel s1 (Label s2) Source # 

Methods

fromLabel :: Proxy# Symbol s1 -> Label s2 #

mkLabel :: forall s. Label s Source #

Creates a label that is determined either by type inference or via -XTypeApplications.