| 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 :: a' =? a => (a -> r) -> a -> a' -> r
- defargs2 :: (a' =? a, b' =? b) => (a -> b -> r) -> a -> b -> a' -> b' -> r
- defargs3 :: (a' =? a, b' =? b, c' =? c) => (a -> b -> c -> r) -> a -> b -> c -> a' -> b' -> c' -> r
- defargs4 :: (a' =? a, b' =? b, c' =? c, d' =? d) => (a -> b -> c -> d -> r) -> a -> b -> c -> d -> a' -> b' -> c' -> d' -> r
- defargs5 :: (a' =? a, b' =? b, c' =? c, d' =? d, e' =? e) => (a -> b -> c -> d -> e -> r) -> a -> b -> c -> d -> e -> a' -> b' -> c' -> d' -> e' -> r
- defargs6 :: (a' =? a, b' =? b, c' =? c, d' =? d, e' =? e, f' =? f) => (a -> b -> c -> d -> e -> f -> r) -> a -> b -> c -> d -> e -> f -> a' -> b' -> c' -> d' -> e' -> f' -> r
- defargs7 :: (a' =? a, b' =? b, c' =? c, d' =? d, e' =? e, f' =? f, g' =? 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 :: (a' =? a, b' =? b, c' =? c, d' =? d, e' =? e, f' =? f, g' =? g, h' =? 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 :: (a' =? a, b' =? b, c' =? c, d' =? d, e' =? e, f' =? f, g' =? g, h' =? h, i' =? 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 :: (a' =? a, b' =? b, c' =? c, d' =? d, e' =? e, f' =? f, g' =? g, h' =? h, i' =? i, j' =? 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 MightBe a' a = In `[Type Def, Type a]` a'
- type (=?) a' a = MightBe a' a
Example
Here is a simple example.
{-# LANGUAGE TypeOperators, FlexibleContexts #-}
import Type.DefArgs
test :: (s =? String, s' =? String) => s -> s' -> String
test = defargs2 (\x y -> x ++ ", " ++ y ++ "!") "hello" "world"
test2 :: (i =? Int, i' =? Int) => i -> i' -> Int
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 :: (a' =? a, b' =? b, c' =? c) => (a -> b -> c -> r) -> a -> b -> c -> a' -> b' -> c' -> r Source
defargs4 :: (a' =? a, b' =? b, c' =? c, d' =? d) => (a -> b -> c -> d -> r) -> a -> b -> c -> d -> a' -> b' -> c' -> d' -> r Source
defargs5 :: (a' =? a, b' =? b, c' =? c, d' =? d, e' =? e) => (a -> b -> c -> d -> e -> r) -> a -> b -> c -> d -> e -> a' -> b' -> c' -> d' -> e' -> r Source
defargs6 :: (a' =? a, b' =? b, c' =? c, d' =? d, e' =? e, f' =? f) => (a -> b -> c -> d -> e -> f -> r) -> a -> b -> c -> d -> e -> f -> a' -> b' -> c' -> d' -> e' -> f' -> r Source
defargs7 :: (a' =? a, b' =? b, c' =? c, d' =? d, e' =? e, f' =? f, g' =? 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 :: (a' =? a, b' =? b, c' =? c, d' =? d, e' =? e, f' =? f, g' =? g, h' =? 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 :: (a' =? a, b' =? b, c' =? c, d' =? d, e' =? e, f' =? f, g' =? g, h' =? h, i' =? 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 :: (a' =? a, b' =? b, c' =? c, d' =? d, e' =? e, f' =? f, g' =? g, h' =? h, i' =? i, j' =? 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