| Copyright | (c) Justin Le 2015 |
|---|---|
| License | MIT |
| Maintainer | justin@jle.im |
| Stability | unstable |
| Portability | non-portable |
| Safe Haskell | Safe |
| Language | Haskell2010 |
GHC.TypeLits.List
Contents
Description
Provides the KnownNats and KnownSymbols typeclasses in analogy to
KnownNat and KnownSymbol from GHC.TypeLits. Also provides
singleton-esque structures for traversing over type-level lists of
Nats and Symbols. Comes with continuation-style reifiers and
existential types for dependent typing usage, and as an analogy with
SomeNat and SomeSymbol.
See typeclass documentations for more information.
- class KnownNats ns where
- data SomeNats :: * where
- data NatList :: [Nat] -> * where
- someNatsVal :: [Integer] -> Maybe SomeNats
- someNatsVal' :: [Integer] -> SomeNats
- reifyNats :: [Integer] -> (forall ns. KnownNats ns => NatList ns -> r) -> r
- traverseNatList :: forall f ns. Applicative f => (forall n. KnownNat n => Proxy n -> f SomeNat) -> NatList ns -> f SomeNats
- traverseNatList' :: forall f. Applicative f => (SomeNat -> f SomeNat) -> SomeNats -> f SomeNats
- traverseNatList_ :: forall f a ns. Applicative f => (forall n. KnownNat n => Proxy n -> f a) -> NatList ns -> f ()
- mapNatList :: (forall n. KnownNat n => Proxy n -> SomeNat) -> NatList ns -> SomeNats
- class KnownSymbols ns where
- symbolsVal :: p ns -> [String]
- symbolsList :: SymbolList ns
- data SomeSymbols :: * where
- SomeSymbols :: KnownSymbols ns => SymbolList ns -> SomeSymbols
- data SymbolList :: [Symbol] -> * where
- ØSL :: SymbolList `[]`
- (:<$) :: (KnownSymbol n, KnownSymbols ns) => Proxy n -> SymbolList ns -> SymbolList (n : ns)
- someSymbolsVal :: [String] -> SomeSymbols
- reifySymbols :: [String] -> (forall ns. KnownSymbols ns => SymbolList ns -> r) -> r
- traverseSymbolList :: forall f ns. Applicative f => (forall n. KnownSymbol n => Proxy n -> f SomeSymbol) -> SymbolList ns -> f SomeSymbols
- traverseSymbolList' :: forall f. Applicative f => (SomeSymbol -> f SomeSymbol) -> SomeSymbols -> f SomeSymbols
- traverseSymbolList_ :: forall f ns. Applicative f => (forall n a. KnownSymbol n => Proxy n -> f a) -> SymbolList ns -> f ()
- mapSymbolList :: (forall n. KnownSymbol n => Proxy n -> SomeSymbol) -> SymbolList ns -> SomeSymbols
KnownNats
class KnownNats ns where Source
is intended to represent that every KnownNats nsNat in the
type-level list ns is itself a KnownNat (meaning, you can use
natVal to get its corresponding Integer).
In practice, just knowing that every item has a KnownNat instance is
not enough; it's nice, but unless you're able to "iterate" over every
Nat in the list, it's of limited use. That's why this class also
provides a constructor for , so that you can produce
a NatList nsNatList for every , which you can iterate over to get
KnownNat nss for every Proxy nn in ns along with the
instances.KnownNat n
It also has an analogy to natVal, natsVal, which lets you get a list
of the represented Integers for, say, .Proxy [1,2,3]
data SomeNats :: * where Source
Represents unknown type-level lists of type-level natural numbers.
It's a NatList, but you don't know what the list contains at
compile-time.
data NatList :: [Nat] -> * where Source
Singleton-esque type for "traversing" over type-level lists of Nats.
Essentially contains a (value-level) list of s, but each Proxy nn
has a KnownNat instance for you to use. At runtime (after type
erasure), is more or less equivalent to a [.Integer]
Typically generated using natsList.
someNatsVal :: [Integer] -> Maybe SomeNats Source
List equivalent of someNatVal. Convert a list of integers into an
unknown type-level list of naturals. Will return Nothing if any of
the given Integers is negative.
someNatsVal' :: [Integer] -> SomeNats Source
Like someNatsVal, but will also go ahead and produce KnownNats
whose integer values are negative. It won't ever error on producing
them, but extra care must be taken when using the produced SomeNats.
reifyNats :: [Integer] -> (forall ns. KnownNats ns => NatList ns -> r) -> r Source
List equivalent of reifyNat. Given a list of integers, takes
a function in an "environment" with a corresponding to
the given list, where every NatList nsn in ns has a KnownNat instance.
Essentially a continuation-style version of SomeNats.
For compatability with reifyNat, be aware that this also produces
s where KnownNat nn is negative, without complaining.
traverseNatList :: forall f ns. Applicative f => (forall n. KnownNat n => Proxy n -> f SomeNat) -> NatList ns -> f SomeNats Source
traverseNatList' :: forall f. Applicative f => (SomeNat -> f SomeNat) -> SomeNats -> f SomeNats Source
Like traverseNatList, but literally actually a
Traversal' , so is usable with lens-library
machinery.SomeNat SomeNats
traverseNatList_ :: forall f a ns. Applicative f => (forall n. KnownNat n => Proxy n -> f a) -> NatList ns -> f () Source
KnownSymbols
class KnownSymbols ns where Source
is intended to represent that every KnownSymbols nsSymbol in the
type-level list ns is itself a KnownSymbol (meaning, you can use
symbolVal to get its corresponding String).
You can use symbolsVal to get the corresponding [ from
String].KnownSymbols ns
For reasons discussed further in the documentation for KnownNats, this
also lets you generate a , in order to iterate over the
type-level list of SymbolList nsSymbols and take advantage of their KnownSymbol
instances.
Instances
| KnownSymbols ([] Symbol) Source | |
| (KnownSymbol n, KnownSymbols ns) => KnownSymbols ((:) Symbol n ns) Source |
data SomeSymbols :: * where Source
Represents unknown type-level lists of Symbols. It's a SymbolList,
but you don't know what the list contains at compile-time.
Constructors
| SomeSymbols :: KnownSymbols ns => SymbolList ns -> SomeSymbols |
data SymbolList :: [Symbol] -> * where Source
Singleton-esque type for "traversing" over type-level lists of
Symbols. Essentially contains a (value-level) list of s,
but each Proxy nn has a KnownSymbol instance for you to use. At runtime
(after type erasure), is more or less equivalent to a [.String]
Typically generated using symbolsList.
Constructors
| ØSL :: SymbolList `[]` | |
| (:<$) :: (KnownSymbol n, KnownSymbols ns) => Proxy n -> SymbolList ns -> SymbolList (n : ns) infixr 5 |
Instances
| Show (SymbolList ns) Source |
someSymbolsVal :: [String] -> SomeSymbols Source
List equivalent of someNatVal. Convert a list of integers into an
unknown type-level list of naturals. Will return Nothing if any of
the given Integers is negative.
reifySymbols :: [String] -> (forall ns. KnownSymbols ns => SymbolList ns -> r) -> r Source
List equivalent of reifyNat. Given a list of integers, takes
a function in an "environment" with a corresponding to
the given list, where every NatList nsn in ns has a KnownNat instance.
Essentially a continuation-style version of SomeSymbols.
traverseSymbolList :: forall f ns. Applicative f => (forall n. KnownSymbol n => Proxy n -> f SomeSymbol) -> SymbolList ns -> f SomeSymbols Source
Utility function for traversing over all of the s in
a Proxy nSymbolList, each with the corresponding KnownSymbol instance
available. Gives the the ability to "change" the represented natural
number to a new one, in a SomeSymbol.
Can be considered a form of a Traversal' .SomeSymbol SomeSymbols
traverseSymbolList' :: forall f. Applicative f => (SomeSymbol -> f SomeSymbol) -> SomeSymbols -> f SomeSymbols Source
Like traverseSymbolList, but literally actually a
Traversal' , so is usable with lens-library
machinery.SomeSymbol SomeSymbols
traverseSymbolList_ :: forall f ns. Applicative f => (forall n a. KnownSymbol n => Proxy n -> f a) -> SymbolList ns -> f () Source
Utility function for traversing over all of the s in
a Proxy nSymbolList, each with the corresponding KnownSymbol instance
available. Results are ignored.
mapSymbolList :: (forall n. KnownSymbol n => Proxy n -> SomeSymbol) -> SymbolList ns -> SomeSymbols Source
Utility function for "mapping" over each of the Symbols in the
SymbolList.