Safe Haskell | None |
---|---|
Language | Haskell2010 |
- sel :: Select s t => s -> t
- selN :: SelectN s n t => s -> Proxy n -> t
- sel1 :: SelectN s 0 t => s -> t
- sel2 :: SelectN s 1 t => s -> t
- sel3 :: SelectN s 2 t => s -> t
- sel4 :: SelectN s 3 t => s -> t
- sel5 :: SelectN s 4 t => s -> t
- sel6 :: SelectN s 5 t => s -> t
- sel7 :: SelectN s 6 t => s -> t
- sel8 :: SelectN s 7 t => s -> t
- sel9 :: SelectN s 8 t => s -> t
- sel10 :: SelectN s 9 t => s -> t
- lastT :: forall s n t. (LengthT s ~ n, SelectN s (n - 1) t) => s -> t
- app :: App f s t => f -> s -> t
- appPoly :: App (Poly a b) s t => (a -> b) -> s -> t
- appN :: AppN f s n t => f -> s -> Proxy n -> t
- mapT :: MapT f s t => f -> s -> t
- mapPolyT :: MapT (Poly a b) s t => (a -> b) -> s -> t
- app1 :: AppN f s 0 t => f -> s -> t
- app2 :: AppN f s 1 t => f -> s -> t
- app3 :: AppN f s 2 t => f -> s -> t
- app4 :: AppN f s 3 t => f -> s -> t
- app5 :: AppN f s 4 t => f -> s -> t
- app6 :: AppN f s 5 t => f -> s -> t
- app7 :: AppN f s 6 t => f -> s -> t
- app8 :: AppN f s 7 t => f -> s -> t
- app9 :: AppN f s 8 t => f -> s -> t
- app10 :: AppN f s 9 t => f -> s -> t
- consT :: ConsT a s t => a -> s -> t
- snocT :: SnocT a s t => a -> s -> t
- appendT :: AppendT s r t => s -> r -> t
- initT :: InitT s t => s -> t
- tailT :: TailT s t => s -> t
- del :: Delete s t => s -> t
- delN :: DeleteN s n t => s -> Proxy n -> t
- del1 :: DeleteN s 0 t => s -> t
- del2 :: DeleteN s 1 t => s -> t
- del3 :: DeleteN s 2 t => s -> t
- del4 :: DeleteN s 3 t => s -> t
- del5 :: DeleteN s 4 t => s -> t
- del6 :: DeleteN s 5 t => s -> t
- del7 :: DeleteN s 6 t => s -> t
- del8 :: DeleteN s 7 t => s -> t
- del9 :: DeleteN s 8 t => s -> t
- del10 :: DeleteN s 9 t => s -> t
- uncurryT :: UnCurryT s t b => s -> t -> b
- curryT :: CurryT s t => s -> t
Selection
sel :: Select s t => s -> t Source #
Takes an n-ary tuple and returns the first element of the requested type
>>>
sel (1,'d','c') :: Char
'd'
convenience functions
sel1 :: SelectN s 0 t => s -> t Source #
Selects the first element in an n-ary tuple
>>>
sel1 (0,'d','c')
0
lastT :: forall s n t. (LengthT s ~ n, SelectN s (n - 1) t) => s -> t Source #
Selects the last element of any n-ary tuple
>>>
lastT (1,2,3,4)
4
>>>
lastT (1,2,3)
3
Application
app :: App f s t => f -> s -> t Source #
Applies a monomorphic function to the first element of an n-ary tuple that matches the type of the argument of the function.
>>>
app not ('d',True)
('d',False)
Sometimes it is necessary to specify the result type, such that the function becomes monomorphic >>> app (+1) (True,5) :: (Bool,Integer) (True,6)
One may also use appPoly
, which doesn't require specifying the result type. However it can only apply functions
to the first element of an n-ary tuple. For application to other elements use appPolyN
or one of its derivatives.
appPoly :: App (Poly a b) s t => (a -> b) -> s -> t Source #
Applies a polymorphic function to the first element of an n-ary tuple. Since the function is polymorphic in its argument it can always be applied to the first element of a tuple.
>>>
appPoly show (5,False)
("5",False)
appN :: AppN f s n t => f -> s -> Proxy n -> t Source #
Applies a function to the element at index n
in an n-ary tuple.
>>>
appN not (Proxy 2) (False,True,False)
(False,True,True)
appN
also works for polymorphic functions
>>>
appN show (5,'c',False) (Proxy :: Proxy 2)
(5,'c',"False")
mapT :: MapT f s t => f -> s -> t Source #
Maps a monomorphic function over each element in an n-ary tuple that matches the type of the argument of the function
>>>
map not (True,5,'c',False)
(False,5,'c',True)
Sometimes it is necessary to specify the result type.
>>>
map (+1) (5,6,7,False) :: (Integer,Integer,Integer,Bool)
(6,7,8,False)
Using mapPolyT
this is not necessary, but this comes with a limitation.
mapPolyT :: MapT (Poly a b) s t => (a -> b) -> s -> t Source #
Applies a polymorphic function to each element in an n-ary tuple. Requires all elements in the tuple to be of the same type.
>>>
mapPolyT (+1) (5,6,7,8)
(6,7,8,9)
>>>
mapPolyT (+1) (5,6,7,False)
No instance for (Num Bool) arising from the literal `5'
convenience functions
app1 :: AppN f s 0 t => f -> s -> t Source #
Applies a function to the first element of an n-ary tuple
>>>
app1 (+1) (5,6,7)
(6,6,7)
Constructing tuples
consT :: ConsT a s t => a -> s -> t Source #
Adds an element to the head of an n-ary tuple
>>>
consT 5 (True,'c')
(5,True,'c')
snocT :: SnocT a s t => a -> s -> t Source #
Adds an element to the back of an n-ary tuple
>>>
snocT 5 (True,'c')
(True,'c',5)
appendT :: AppendT s r t => s -> r -> t Source #
Appends two n-ary tuple into one larger tuple
>>>
appendT (5,'c') ('d',False)
(5,'c','d',False)
initT :: InitT s t => s -> t Source #
Takes an n-ary tuple and returns the same tuple minus the first element.
>>>
initT (1,2,3,4)
(1,2,3)
Works only only tuples of size at least 3
>>>
initT (1,2)
Couldn't match type `2 ':<= 3' with `2 ':>= 3'
tailT :: TailT s t => s -> t Source #
Takes an n-ary tuple and returns the same tuple minus the first element.
>>>
tailT (1,2,3,4)
(2,3,4)
Works only only tuples of size at least 3
>>>
tailT (1,2)
Couldn't match type `2 ':<= 3' with `2 ':>= 3'
Deletion
del :: Delete s t => s -> t Source #
Deletes the first element in an n-ary tuple whose type does not exist in the target type
>>>
del ('c',False,5) :: (Char,Bool)
('c',False)
delN :: DeleteN s n t => s -> Proxy n -> t Source #
Deletes an element specified by an index in an n-ary tuple
>>>
delN ('c',False,5) (Proxy :: Proxy 1)
('c',5)
convenience functions
del1 :: DeleteN s 0 t => s -> t Source #
Deletes the first element of an n-ary tuple
>>>
del1 ('c',False,5)
(False,5)