Copyright | Clinton Mead 2017 |
---|---|
License | MIT |
Maintainer | clintonmead@gmail.com |
Stability | experimental |
Portability | GHC |
Safe Haskell | Safe |
Language | Haskell2010 |
Control.IndexT
Description
This package is useful for dealing with for what I have called "indexed types". This is perhaps not a great choice of name (alternative suggestions welcome) but basically I'm talking about types where you can "index" them like an array. A tuple is a good example.
This particular module gives you a type function IndexT
that allows you to get the type of the say, third
element of a tuple.
But the other modules in this package, Control.IndexT.Tuple and Control.IndexT.Function, build on this.
For example, occasionally you'll want to write a constraint like this:
t ~ (t1,t2)
i.e. t
is a pair. But if t1
and t2
are not in scope, GHC will complain.
This package contains some type family and class defined constraints that allow you to
make constraints like "t
is a pair".
The type families are open, so you can extend this module for your own data types.
More detailed usage information is in the documentation, both below. and also in Control.IndexT.Tuple.
Currently this library deals with tuples up to length 15 and functions with up to 15 arguments. Let me know if you need anything bigger.
Documentation
type family IndexT (i :: Nat) a Source #
IndexT
is the core type family of this module. IndexT n a
gets the type of the "nth" element of a
.
In this module, IndexT
is defined on tuples and functions, and is zero based.
So
IndexT 0 (a, b, c) == a
and
IndexT 0 (a -> b -> c) == a
Note the following:
IndexT 1 (a -> b -> c) == b IndexT 2 (a, b, c) == c
but...
IndexT 2 (a -> b -> c) /= c -- (it's actually not defined)
This is because the way functions are defined. Consider a function of three arguments:
f :: a -> b -> c -> d
For this function, we want:
IndexT 2 (a -> b -> c -> d) == c
But if we defined IndexT
like the following:
IndexT 2 (a -> b -> c) = c
Then we would find that:
IndexT 2 (a -> b -> c -> d) == IndexT 2 (a -> b -> (c -> d)) == (c -> d)
Which is not right. For this reason, IndexT
can not get the "result" type of functions, you'll need to use ResultT
for that.
Instances
type IndexT 0 (Identity a) Source # | |
type IndexT 0 (a -> _) Source # | |
type IndexT 0 (a, _) Source # | |
type IndexT 1 (_1 -> a -> _) Source # | |
type IndexT 1 (_, a) Source # | |
type IndexT 2 (_2 -> _1 -> a -> _) Source # | |
type IndexT 3 (_3 -> _2 -> _1 -> a -> _) Source # | |
type IndexT 4 (_4 -> _3 -> _2 -> _1 -> a -> _) Source # | |
type IndexT 5 (_5 -> _4 -> _3 -> _2 -> _1 -> a -> _) Source # | |
type IndexT 6 (_6 -> _5 -> _4 -> _3 -> _2 -> _1 -> a -> _) Source # | |
type IndexT 7 (_7 -> _6 -> _5 -> _4 -> _3 -> _2 -> _1 -> a -> _) Source # | |
type IndexT 8 (_8 -> _7 -> _6 -> _5 -> _4 -> _3 -> _2 -> _1 -> a -> _) Source # | |
type IndexT 9 (_9 -> _8 -> _7 -> _6 -> _5 -> _4 -> _3 -> _2 -> _1 -> a -> _) Source # | |
type IndexT 10 (_10 -> _9 -> _8 -> _7 -> _6 -> _5 -> _4 -> _3 -> _2 -> _1 -> a -> _) Source # | |
type IndexT 11 (_11 -> _10 -> _9 -> _8 -> _7 -> _6 -> _5 -> _4 -> _3 -> _2 -> _1 -> a -> _) Source # | |
type IndexT 12 (_12 -> _11 -> _10 -> _9 -> _8 -> _7 -> _6 -> _5 -> _4 -> _3 -> _2 -> _1 -> a -> _) Source # | |
type IndexT 13 (_13 -> _12 -> _11 -> _10 -> _9 -> _8 -> _7 -> _6 -> _5 -> _4 -> _3 -> _2 -> _1 -> a -> _) Source # | |
type IndexT 0 (a, _1, _) Source # | |
type IndexT 1 (_1, a, _) Source # | |
type IndexT 2 (_1, _, a) Source # | |
type IndexT 0 (a, _2, _1, _) Source # | |
type IndexT 1 (_2, a, _1, _) Source # | |
type IndexT 2 (_2, _1, a, _) Source # | |
type IndexT 3 (_2, _1, _, a) Source # | |
type IndexT 0 (a, _3, _2, _1, _) Source # | |
type IndexT 1 (_3, a, _2, _1, _) Source # | |
type IndexT 2 (_3, _2, a, _1, _) Source # | |
type IndexT 3 (_3, _2, _1, a, _) Source # | |
type IndexT 4 (_3, _2, _1, _, a) Source # | |
type IndexT 0 (a, _4, _3, _2, _1, _) Source # | |
type IndexT 1 (_4, a, _3, _2, _1, _) Source # | |
type IndexT 2 (_4, _3, a, _2, _1, _) Source # | |
type IndexT 3 (_4, _3, _2, a, _1, _) Source # | |
type IndexT 4 (_4, _3, _2, _1, a, _) Source # | |
type IndexT 5 (_4, _3, _2, _1, _, a) Source # | |
type IndexT 0 (a, _5, _4, _3, _2, _1, _) Source # | |
type IndexT 1 (_5, a, _4, _3, _2, _1, _) Source # | |
type IndexT 2 (_5, _4, a, _3, _2, _1, _) Source # | |
type IndexT 3 (_5, _4, _3, a, _2, _1, _) Source # | |
type IndexT 4 (_5, _4, _3, _2, a, _1, _) Source # | |
type IndexT 5 (_5, _4, _3, _2, _1, a, _) Source # | |
type IndexT 6 (_5, _4, _3, _2, _1, _, a) Source # | |
type IndexT 0 (a, _6, _5, _4, _3, _2, _1, _) Source # | |
type IndexT 1 (_6, a, _5, _4, _3, _2, _1, _) Source # | |
type IndexT 2 (_6, _5, a, _4, _3, _2, _1, _) Source # | |
type IndexT 3 (_6, _5, _4, a, _3, _2, _1, _) Source # | |
type IndexT 4 (_6, _5, _4, _3, a, _2, _1, _) Source # | |
type IndexT 5 (_6, _5, _4, _3, _2, a, _1, _) Source # | |
type IndexT 6 (_6, _5, _4, _3, _2, _1, a, _) Source # | |
type IndexT 7 (_6, _5, _4, _3, _2, _1, _, a) Source # | |
type IndexT 0 (a, _7, _6, _5, _4, _3, _2, _1, _) Source # | |
type IndexT 1 (_7, a, _6, _5, _4, _3, _2, _1, _) Source # | |
type IndexT 2 (_7, _6, a, _5, _4, _3, _2, _1, _) Source # | |
type IndexT 3 (_7, _6, _5, a, _4, _3, _2, _1, _) Source # | |
type IndexT 4 (_7, _6, _5, _4, a, _3, _2, _1, _) Source # | |
type IndexT 5 (_7, _6, _5, _4, _3, a, _2, _1, _) Source # | |
type IndexT 6 (_7, _6, _5, _4, _3, _2, a, _1, _) Source # | |
type IndexT 7 (_7, _6, _5, _4, _3, _2, _1, a, _) Source # | |
type IndexT 8 (_7, _6, _5, _4, _3, _2, _1, _, a) Source # | |
type IndexT 0 (a, _8, _7, _6, _5, _4, _3, _2, _1, _) Source # | |
type IndexT 1 (_8, a, _7, _6, _5, _4, _3, _2, _1, _) Source # | |
type IndexT 2 (_8, _7, a, _6, _5, _4, _3, _2, _1, _) Source # | |
type IndexT 3 (_8, _7, _6, a, _5, _4, _3, _2, _1, _) Source # | |
type IndexT 4 (_8, _7, _6, _5, a, _4, _3, _2, _1, _) Source # | |
type IndexT 5 (_8, _7, _6, _5, _4, a, _3, _2, _1, _) Source # | |
type IndexT 6 (_8, _7, _6, _5, _4, _3, a, _2, _1, _) Source # | |
type IndexT 7 (_8, _7, _6, _5, _4, _3, _2, a, _1, _) Source # | |
type IndexT 8 (_8, _7, _6, _5, _4, _3, _2, _1, a, _) Source # | |
type IndexT 9 (_8, _7, _6, _5, _4, _3, _2, _1, _, a) Source # | |
type IndexT 0 (a, _9, _8, _7, _6, _5, _4, _3, _2, _1, _) Source # | |
type IndexT 1 (_9, a, _8, _7, _6, _5, _4, _3, _2, _1, _) Source # | |
type IndexT 2 (_9, _8, a, _7, _6, _5, _4, _3, _2, _1, _) Source # | |
type IndexT 3 (_9, _8, _7, a, _6, _5, _4, _3, _2, _1, _) Source # | |
type IndexT 4 (_9, _8, _7, _6, a, _5, _4, _3, _2, _1, _) Source # | |
type IndexT 5 (_9, _8, _7, _6, _5, a, _4, _3, _2, _1, _) Source # | |
type IndexT 6 (_9, _8, _7, _6, _5, _4, a, _3, _2, _1, _) Source # | |
type IndexT 7 (_9, _8, _7, _6, _5, _4, _3, a, _2, _1, _) Source # | |
type IndexT 8 (_9, _8, _7, _6, _5, _4, _3, _2, a, _1, _) Source # | |
type IndexT 9 (_9, _8, _7, _6, _5, _4, _3, _2, _1, a, _) Source # | |
type IndexT 10 (_9, _8, _7, _6, _5, _4, _3, _2, _1, _, a) Source # | |
type IndexT 0 (a, _10, _9, _8, _7, _6, _5, _4, _3, _2, _1, _) Source # | |
type IndexT 1 (_10, a, _9, _8, _7, _6, _5, _4, _3, _2, _1, _) Source # | |
type IndexT 2 (_10, _9, a, _8, _7, _6, _5, _4, _3, _2, _1, _) Source # | |
type IndexT 3 (_10, _9, _8, a, _7, _6, _5, _4, _3, _2, _1, _) Source # | |
type IndexT 4 (_10, _9, _8, _7, a, _6, _5, _4, _3, _2, _1, _) Source # | |
type IndexT 5 (_10, _9, _8, _7, _6, a, _5, _4, _3, _2, _1, _) Source # | |
type IndexT 6 (_10, _9, _8, _7, _6, _5, a, _4, _3, _2, _1, _) Source # | |
type IndexT 7 (_10, _9, _8, _7, _6, _5, _4, a, _3, _2, _1, _) Source # | |
type IndexT 8 (_10, _9, _8, _7, _6, _5, _4, _3, a, _2, _1, _) Source # | |
type IndexT 9 (_10, _9, _8, _7, _6, _5, _4, _3, _2, a, _1, _) Source # | |
type IndexT 10 (_10, _9, _8, _7, _6, _5, _4, _3, _2, _1, a, _) Source # | |
type IndexT 11 (_10, _9, _8, _7, _6, _5, _4, _3, _2, _1, _, a) Source # | |
type IndexT 0 (a, _11, _10, _9, _8, _7, _6, _5, _4, _3, _2, _1, _) Source # | |
type IndexT 1 (_11, a, _10, _9, _8, _7, _6, _5, _4, _3, _2, _1, _) Source # | |
type IndexT 2 (_11, _10, a, _9, _8, _7, _6, _5, _4, _3, _2, _1, _) Source # | |
type IndexT 3 (_11, _10, _9, a, _8, _7, _6, _5, _4, _3, _2, _1, _) Source # | |
type IndexT 4 (_11, _10, _9, _8, a, _7, _6, _5, _4, _3, _2, _1, _) Source # | |
type IndexT 5 (_11, _10, _9, _8, _7, a, _6, _5, _4, _3, _2, _1, _) Source # | |
type IndexT 6 (_11, _10, _9, _8, _7, _6, a, _5, _4, _3, _2, _1, _) Source # | |
type IndexT 7 (_11, _10, _9, _8, _7, _6, _5, a, _4, _3, _2, _1, _) Source # | |
type IndexT 8 (_11, _10, _9, _8, _7, _6, _5, _4, a, _3, _2, _1, _) Source # | |
type IndexT 9 (_11, _10, _9, _8, _7, _6, _5, _4, _3, a, _2, _1, _) Source # | |
type IndexT 10 (_11, _10, _9, _8, _7, _6, _5, _4, _3, _2, a, _1, _) Source # | |
type IndexT 11 (_11, _10, _9, _8, _7, _6, _5, _4, _3, _2, _1, a, _) Source # | |
type IndexT 12 (_11, _10, _9, _8, _7, _6, _5, _4, _3, _2, _1, _, a) Source # | |
type IndexT 0 (a, _12, _11, _10, _9, _8, _7, _6, _5, _4, _3, _2, _1, _) Source # | |
type IndexT 1 (_12, a, _11, _10, _9, _8, _7, _6, _5, _4, _3, _2, _1, _) Source # | |
type IndexT 2 (_12, _11, a, _10, _9, _8, _7, _6, _5, _4, _3, _2, _1, _) Source # | |
type IndexT 3 (_12, _11, _10, a, _9, _8, _7, _6, _5, _4, _3, _2, _1, _) Source # | |
type IndexT 4 (_12, _11, _10, _9, a, _8, _7, _6, _5, _4, _3, _2, _1, _) Source # | |
type IndexT 5 (_12, _11, _10, _9, _8, a, _7, _6, _5, _4, _3, _2, _1, _) Source # | |
type IndexT 6 (_12, _11, _10, _9, _8, _7, a, _6, _5, _4, _3, _2, _1, _) Source # | |
type IndexT 7 (_12, _11, _10, _9, _8, _7, _6, a, _5, _4, _3, _2, _1, _) Source # | |
type IndexT 8 (_12, _11, _10, _9, _8, _7, _6, _5, a, _4, _3, _2, _1, _) Source # | |
type IndexT 9 (_12, _11, _10, _9, _8, _7, _6, _5, _4, a, _3, _2, _1, _) Source # | |
type IndexT 10 (_12, _11, _10, _9, _8, _7, _6, _5, _4, _3, a, _2, _1, _) Source # | |
type IndexT 11 (_12, _11, _10, _9, _8, _7, _6, _5, _4, _3, _2, a, _1, _) Source # | |
type IndexT 12 (_12, _11, _10, _9, _8, _7, _6, _5, _4, _3, _2, _1, a, _) Source # | |
type IndexT 13 (_12, _11, _10, _9, _8, _7, _6, _5, _4, _3, _2, _1, _, a) Source # | |
type IndexT 0 (a, _13, _12, _11, _10, _9, _8, _7, _6, _5, _4, _3, _2, _1, _) Source # | |
type IndexT 1 (_13, a, _12, _11, _10, _9, _8, _7, _6, _5, _4, _3, _2, _1, _) Source # | |
type IndexT 2 (_13, _12, a, _11, _10, _9, _8, _7, _6, _5, _4, _3, _2, _1, _) Source # | |
type IndexT 3 (_13, _12, _11, a, _10, _9, _8, _7, _6, _5, _4, _3, _2, _1, _) Source # | |
type IndexT 4 (_13, _12, _11, _10, a, _9, _8, _7, _6, _5, _4, _3, _2, _1, _) Source # | |
type IndexT 5 (_13, _12, _11, _10, _9, a, _8, _7, _6, _5, _4, _3, _2, _1, _) Source # | |
type IndexT 6 (_13, _12, _11, _10, _9, _8, a, _7, _6, _5, _4, _3, _2, _1, _) Source # | |
type IndexT 7 (_13, _12, _11, _10, _9, _8, _7, a, _6, _5, _4, _3, _2, _1, _) Source # | |
type IndexT 8 (_13, _12, _11, _10, _9, _8, _7, _6, a, _5, _4, _3, _2, _1, _) Source # | |
type IndexT 9 (_13, _12, _11, _10, _9, _8, _7, _6, _5, a, _4, _3, _2, _1, _) Source # | |
type IndexT 10 (_13, _12, _11, _10, _9, _8, _7, _6, _5, _4, a, _3, _2, _1, _) Source # | |
type IndexT 11 (_13, _12, _11, _10, _9, _8, _7, _6, _5, _4, _3, a, _2, _1, _) Source # | |
type IndexT 12 (_13, _12, _11, _10, _9, _8, _7, _6, _5, _4, _3, _2, a, _1, _) Source # | |
type IndexT 13 (_13, _12, _11, _10, _9, _8, _7, _6, _5, _4, _3, _2, _1, a, _) Source # | |
type IndexT 14 (_13, _12, _11, _10, _9, _8, _7, _6, _5, _4, _3, _2, _1, _, a) Source # | |