| Copyright | (c) Yusuke Matsushita 2014 |
|---|---|
| License | BSD3 |
| Maintainer | Yusuke Matsushita |
| Stability | provisional |
| Portability | portable |
| Safe Haskell | Trustworthy |
| Language | Haskell2010 |
Type.DefArgs
Contents
Description
Default arguments in Haskell.
- data Def = Def
- defarg :: DefArg r a a' => (a -> r) -> a -> a' -> r
- defargs2 :: DefArgs2 r a b a' b' => (a -> b -> r) -> a -> b -> a' -> b' -> r
- defargs3 :: DefArgs3 r a b c a' b' c' => (a -> b -> c -> r) -> a -> b -> c -> a' -> b' -> c' -> r
- defargs4 :: DefArgs4 r a b c d a' b' c' d' => (a -> b -> c -> d -> r) -> a -> b -> c -> d -> a' -> b' -> c' -> d' -> r
- defargs5 :: DefArgs5 r a b c d e a' b' c' d' e' => (a -> b -> c -> d -> e -> r) -> a -> b -> c -> d -> e -> a' -> b' -> c' -> d' -> e' -> r
- defargs6 :: DefArgs6 r a b c d e f a' b' c' d' e' f' => (a -> b -> c -> d -> e -> f -> r) -> a -> b -> c -> d -> e -> f -> a' -> b' -> c' -> d' -> e' -> f' -> r
- defargs7 :: DefArgs7 r a b c d e f g a' b' c' d' e' f' g' => (a -> b -> c -> d -> e -> f -> g -> r) -> a -> b -> c -> d -> e -> f -> g -> a' -> b' -> c' -> d' -> e' -> f' -> g' -> r
- defargs8 :: DefArgs8 r a b c d e f g h a' b' c' d' e' f' g' h' => (a -> b -> c -> d -> e -> f -> g -> h -> r) -> a -> b -> c -> d -> e -> f -> g -> h -> a' -> b' -> c' -> d' -> e' -> f' -> g' -> h' -> r
- defargs9 :: DefArgs9 r a b c d e f g h i a' b' c' d' e' f' g' h' i' => (a -> b -> c -> d -> e -> f -> g -> h -> i -> r) -> a -> b -> c -> d -> e -> f -> g -> h -> i -> a' -> b' -> c' -> d' -> e' -> f' -> g' -> h' -> i' -> r
- defargs10 :: DefArgs10 r a b c d e f g h i j a' b' c' d' e' f' g' h' i' j' => (a -> b -> c -> d -> e -> f -> g -> h -> i -> j -> r) -> a -> b -> c -> d -> e -> f -> g -> h -> i -> j -> a' -> b' -> c' -> d' -> e' -> f' -> g' -> h' -> i' -> j' -> r
- type DefArg r a a' = Good (a -> r) (a * Nil) (a' -> r)
- type DefArgs2 r a b a' b' = Good (a -> b -> r) (a * (b * Nil)) (a' -> b' -> r)
- type DefArgs3 r a b c a' b' c' = Good (a -> b -> c -> r) (a * (b * (c * Nil))) (a' -> b' -> c' -> r)
- type DefArgs4 r a b c d a' b' c' d' = Good (a -> b -> c -> d -> r) (a * (b * (c * (d * Nil)))) (a' -> b' -> c' -> d' -> r)
- type DefArgs5 r a b c d e a' b' c' d' e' = Good (a -> b -> c -> d -> e -> r) (a * (b * (c * (d * (e * Nil))))) (a' -> b' -> c' -> d' -> e' -> r)
- type DefArgs6 r a b c d e f a' b' c' d' e' f' = Good (a -> b -> c -> d -> e -> f -> r) (a * (b * (c * (d * (e * (f * Nil)))))) (a' -> b' -> c' -> d' -> e' -> f' -> r)
- type DefArgs7 r a b c d e f g a' b' c' d' e' f' g' = Good (a -> b -> c -> d -> e -> f -> g -> r) (a * (b * (c * (d * (e * (f * (g * Nil))))))) (a' -> b' -> c' -> d' -> e' -> f' -> g' -> r)
- type DefArgs8 r a b c d e f g h a' b' c' d' e' f' g' h' = Good (a -> b -> c -> d -> e -> f -> g -> h -> r) (a * (b * (c * (d * (e * (f * (g * (h * Nil)))))))) (a' -> b' -> c' -> d' -> e' -> f' -> g' -> h' -> r)
- type DefArgs9 r a b c d e f g h i a' b' c' d' e' f' g' h' i' = Good (a -> b -> c -> d -> e -> f -> g -> h -> i -> r) (a * (b * (c * (d * (e * (f * (g * (h * (i * Nil))))))))) (a' -> b' -> c' -> d' -> e' -> f' -> g' -> h' -> i' -> r)
- type DefArgs10 r a b c d e f g h i j a' b' c' d' e' f' g' h' i' j' = Good (a -> b -> c -> d -> e -> f -> g -> h -> i -> j -> r) (a * (b * (c * (d * (e * (f * (g * (h * (i * (j * Nil)))))))))) (a' -> b' -> c' -> d' -> e' -> f' -> g' -> h' -> i' -> j' -> r)
Example
Here is a simple example.
{-# LANGUAGE NoMonomorphismRestriction #-}
import Type.DefArgs
test = defargs2 (\x y -> x ++ ", " ++ y ++ "!") "hello" "world"
test2 = defargs2 (+) (10 :: Int) 100
main = do
putStrLn $ test Def Def
putStrLn $ test "good morning" Def
putStrLn $ test Def "kitty"
putStrLn $ test "oh" "yeah"
print $ test2 (90 :: Int) Def
This is the result.
hello, world! good morning, world! hello, kitty! oh, yeah! 190
Def
When used as an argument, Def will be replaced with the corresponding default value by defarg, defargs2, ..., and defargs10.
Constructors
| Def |
Converters
Given a function, these converters provide every argument of the function with a default value.
defarg is used for a function of one argument, defargs2 is used for a function of two arguments, and so on.
The converters require concrete types for the type variables a, b, c, ...;
they need concrete types in order to judge whether a type is Def or non-Def.
Internally, the judgment is made by cluss.
defargs3 :: DefArgs3 r a b c a' b' c' => (a -> b -> c -> r) -> a -> b -> c -> a' -> b' -> c' -> r Source
defargs4 :: DefArgs4 r a b c d a' b' c' d' => (a -> b -> c -> d -> r) -> a -> b -> c -> d -> a' -> b' -> c' -> d' -> r Source
defargs5 :: DefArgs5 r a b c d e a' b' c' d' e' => (a -> b -> c -> d -> e -> r) -> a -> b -> c -> d -> e -> a' -> b' -> c' -> d' -> e' -> r Source
defargs6 :: DefArgs6 r a b c d e f a' b' c' d' e' f' => (a -> b -> c -> d -> e -> f -> r) -> a -> b -> c -> d -> e -> f -> a' -> b' -> c' -> d' -> e' -> f' -> r Source
defargs7 :: DefArgs7 r a b c d e f g a' b' c' d' e' f' g' => (a -> b -> c -> d -> e -> f -> g -> r) -> a -> b -> c -> d -> e -> f -> g -> a' -> b' -> c' -> d' -> e' -> f' -> g' -> r Source
defargs8 :: DefArgs8 r a b c d e f g h a' b' c' d' e' f' g' h' => (a -> b -> c -> d -> e -> f -> g -> h -> r) -> a -> b -> c -> d -> e -> f -> g -> h -> a' -> b' -> c' -> d' -> e' -> f' -> g' -> h' -> r Source
defargs9 :: DefArgs9 r a b c d e f g h i a' b' c' d' e' f' g' h' i' => (a -> b -> c -> d -> e -> f -> g -> h -> i -> r) -> a -> b -> c -> d -> e -> f -> g -> h -> i -> a' -> b' -> c' -> d' -> e' -> f' -> g' -> h' -> i' -> r Source
defargs10 :: DefArgs10 r a b c d e f g h i j a' b' c' d' e' f' g' h' i' j' => (a -> b -> c -> d -> e -> f -> g -> h -> i -> j -> r) -> a -> b -> c -> d -> e -> f -> g -> h -> i -> j -> a' -> b' -> c' -> d' -> e' -> f' -> g' -> h' -> i' -> j' -> r Source
Constraints
type DefArgs3 r a b c a' b' c' = Good (a -> b -> c -> r) (a * (b * (c * Nil))) (a' -> b' -> c' -> r) Source
type DefArgs4 r a b c d a' b' c' d' = Good (a -> b -> c -> d -> r) (a * (b * (c * (d * Nil)))) (a' -> b' -> c' -> d' -> r) Source
type DefArgs5 r a b c d e a' b' c' d' e' = Good (a -> b -> c -> d -> e -> r) (a * (b * (c * (d * (e * Nil))))) (a' -> b' -> c' -> d' -> e' -> r) Source
type DefArgs6 r a b c d e f a' b' c' d' e' f' = Good (a -> b -> c -> d -> e -> f -> r) (a * (b * (c * (d * (e * (f * Nil)))))) (a' -> b' -> c' -> d' -> e' -> f' -> r) Source
type DefArgs7 r a b c d e f g a' b' c' d' e' f' g' = Good (a -> b -> c -> d -> e -> f -> g -> r) (a * (b * (c * (d * (e * (f * (g * Nil))))))) (a' -> b' -> c' -> d' -> e' -> f' -> g' -> r) Source
type DefArgs8 r a b c d e f g h a' b' c' d' e' f' g' h' = Good (a -> b -> c -> d -> e -> f -> g -> h -> r) (a * (b * (c * (d * (e * (f * (g * (h * Nil)))))))) (a' -> b' -> c' -> d' -> e' -> f' -> g' -> h' -> r) Source