Safe Haskell | None |
---|---|
Language | Haskell2010 |
The core subset of the libary interface. Data.Ruin offers more.
The basic idea of this module is that anonymous records are only used to emulate named function arguments. Thus, this module provides very little in the way of creating records; it expects that you'll declare and build your record types as usual.
The most solid use case for this module is a data type for parsing the command-line.
- data s :@ a
- dub :: Label s -> a -> s :@ a
- undub :: Label s -> (s :@ a) -> a
- rpat :: QuasiQuoter
- class Build t
- rna :: QuasiQuoter
- rnaA :: QuasiQuoter
- (<@) :: l -> r -> Pair l r
- rfrom :: forall h rc t. (Hoid h rc, rc `IsSymmetricRecordOf` t, Build t) => rc -> t
- rsym :: (l `IsSymmetricRecordOf` r, Build r) => l -> r
- rup :: forall t rc. (Build t, rc `IsSubtypeOf` t) => rc -> t
- rtoA :: forall h t rc i. (Hoid h t, Applicative i, SymmetricRecordsA t i rc, Build t) => rc -> i t
- rupA :: forall t rc i. (Applicative i, Build t, GivesThese (Fields t) i (GiveAllItHasA rc)) => rc -> i t
- class NoWarnUnusedTopBind t where
- makeRecords :: [Name] -> Q [Dec]
Records
A record type with a single field.
(~) Symbol s1 s2 => Has s1 ((:@) s2 a) Source # | |
Functor ((:@) s) Source # | |
Generic1 ((:@) s) Source # | |
Eq a => Eq ((:@) s a) Source # | |
(Data a, KnownSymbol s) => Data ((:@) s a) Source # | |
Ord a => Ord ((:@) s a) Source # | |
(KnownSymbol s, Show a) => Show ((:@) s a) Source # | |
Generic ((:@) s a) Source # | |
(Lift a, KnownSymbol s) => Lift ((:@) s a) Source # | |
Binary a => Binary ((:@) s a) Source # | |
Serialize a => Serialize ((:@) s a) Source # | |
NFData a => NFData ((:@) s a) Source # | |
Build ((:@) s a) Source # | |
type FieldType s1 ((:@) s2 a) Source # | |
type Rep1 ((:@) s) Source # | |
type Rep ((:@) s a) Source # | |
type Fields ((:@) s a) Source # | |
type Shape ((:@) s _) o Source # | |
Accessing parts of records
Building records
Record types: product types where each factor has a static name
(i.e. the Fields
).
Build () Source # | |
Build a => Build (Tup1 a) Source # | |
(KnownFD fd, Hoid FD ([(Symbol, *)] -> FD) MkFD fd) => Build (R fd) Source # | |
TypeError Constraint (NoFun (* -> Constraint) Build) => Build (a -> b) Source # | This is a non-instance. |
(DisjointFields a b, Lemma_AppendGivesThese (Fields a), Build a, Build b) => Build (a, b) Source # | |
Build ((:@) s a) Source # | |
TypeError Constraint NoBuildPair => Build (Pair l r) Source # | This is a non-instance. |
Build ((a, b), c) => Build (a, b, c) Source # | |
Build ((a, b), (c, d)) => Build (a, b, c, d) Source # | |
Build ((a, b, c), (d, e)) => Build (a, b, c, d, e) Source # | |
Build ((a, b, c), (d, e, f)) => Build (a, b, c, d, e, f) Source # | |
Build ((a, b, c, d), (e, f, g)) => Build (a, b, c, d, e, f, g) Source # | |
Build ((a, b, c, d), (e, f, g, h)) => Build (a, b, c, d, e, f, g, h) Source # | |
rna :: QuasiQuoter Source #
rnaA :: QuasiQuoter Source #
rnaA
is like rna
, but it only works for expressions and it
only works inside an Applicative
.
Pure Combinators
rsym :: (l `IsSymmetricRecordOf` r, Build r) => l -> r Source #
An isomorphism based on rup
, when the two record types have a
symmetric subtyping relation.
- Isomorphism
forall t s. ( s '
IsSubtypeOf
' t,Build
s , t 'IsSubtypeOf
' s,Build
t ) =>rsym
. id @t .rsym
= id @s
rup :: forall t rc. (Build t, rc `IsSubtypeOf` t) => rc -> t Source #
Applicative
Combinators
rtoA :: forall h t rc i. (Hoid h t, Applicative i, SymmetricRecordsA t i rc, Build t) => rc -> i t Source #
rupA :: forall t rc i. (Applicative i, Build t, GivesThese (Fields t) i (GiveAllItHasA rc)) => rc -> i t Source #
Conveniences
Avoid unused selectors
class NoWarnUnusedTopBind t where Source #
Merely a receptacle in which the user can syntactially use a
record selector to avoid the -Wunused-top-bind
warning without
having to export the record selector.
{-# OPTIONS_GHC -Werror -Wall #-} module Foo (Bar(MkBar)) where data Bar = MkBar {x,y :: Int} instanceNoWarnUnusedTopBind
Bar wherenoWarnUnusedTopBind
MkBar{x=_,y=_} = () instanceHas
"x" Bar instanceHas
"y" Bar instanceBuild
Bar where {-# INLINErupEval
#-}rupEval
=genericRupEval
x
and y
in that example are neither exported nor really used,
but there will be no warnings.
An explicit instance of NFData
, for example, will
often use a similar record pattern that serves to use the
selectors. On the other hand, most such instances are now quite
conveient to implicitly derive, so this NoWarnUnusedTopBind
class
may be the most obvious way to inconsequentially "use" a record
selector so as to avoid the -Wunused-top-bind
warning.
noWarnUnusedTopBind :: Hoid t a => a -> () Source #
Splice
makeRecords :: [Name] -> Q [Dec] Source #
Declare the straight-forward Has
and Build
instances for a
record type. A data type is a record type if it has exactly one
constructor and that constructor is declared using record syntax.
An instance of a data family can be a record type; refer to that type by the name of the instance's constructor.
The generated code relies on the GHC.Generics defaults in the same way a user would; it merely relieves you from enumerating the per-field instances.
Also, the splice will declare the instances in the style of Data.Ruin.ClosedHas.