diff options
author | Marvin Borner | 2022-07-18 01:44:38 +0200 |
---|---|---|
committer | Marvin Borner | 2022-07-18 01:44:38 +0200 |
commit | 745147f88f400cced478dd588a2dfd7a7c2140a8 (patch) | |
tree | 3c8e963275ef111b21315a662fd601286f4e123b /std/Pair.bruijn | |
parent | 313e883f5e2146a2005ae0ed6a36af835cbbc961 (diff) |
Moved/improved standard library
and other things
Diffstat (limited to 'std/Pair.bruijn')
-rw-r--r-- | std/Pair.bruijn | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/std/Pair.bruijn b/std/Pair.bruijn new file mode 100644 index 0000000..75d8680 --- /dev/null +++ b/std/Pair.bruijn @@ -0,0 +1,26 @@ +# MIT License, Copyright (c) 2022 Marvin Borner + +:import std/Combinator . + +# pairs two expressions into one +pair [[[0 2 1]]] + +# extracts first expression from pair +fst [0 T] +:test fst (pair [[0]] [[1]]) = [[0]] + +# extracts second expression from pair +snd [0 F] +:test snd (pair [[0]] [[1]]) = [[1]] + +# applies both elements of a pair to a function +uncurry [[1 (fst 0) (snd 0)]] +:test uncurry W (pair [[0]] [[1]]) = [[1]] + +# applies a function to the pair of two values +curry [[[2 (pair 1 0)]]] +:test curry fst [[0]] [[1]] = [[0]] + +# swaps the values of a pair +swap [pair (snd 0) (fst 0)] +:test swap (pair [[0]] [[1]]) = pair [[1]] [[0]] |