From 745147f88f400cced478dd588a2dfd7a7c2140a8 Mon Sep 17 00:00:00 2001 From: Marvin Borner Date: Mon, 18 Jul 2022 01:44:38 +0200 Subject: Moved/improved standard library and other things --- std/Pair.bruijn | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 std/Pair.bruijn (limited to 'std/Pair.bruijn') 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]] -- cgit v1.2.3