diff options
author | Marvin Borner | 2024-03-02 16:16:51 +0100 |
---|---|---|
committer | Marvin Borner | 2024-03-02 19:30:59 +0100 |
commit | ca3907431bfde5aa0715945222ce777d72e6b411 (patch) | |
tree | 5399b72899c5d66f94782892ba9dbf29839aca22 /std/List.bruijn | |
parent | 46cc8f5b0da07d8c7cb354c7b7a281b8d0f3d7bf (diff) |
Docs & samples
Diffstat (limited to 'std/List.bruijn')
-rw-r--r-- | std/List.bruijn | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/std/List.bruijn b/std/List.bruijn index fe4b6f9..56e9157 100644 --- a/std/List.bruijn +++ b/std/List.bruijn @@ -1,6 +1,7 @@ # MIT License, Copyright (c) 2022 Marvin Borner # Lists in Church/Boehm-Berarducci encoding using pairs # implementations are generally lazy (except when they're broken) +# TODO: look into https://hbr.github.io/Lambda-Calculus/lambda2/lambda.html#lists, has more elegant mapping :import std/Combinator . :import std/Pair P @@ -244,7 +245,9 @@ concat foldr append empty ⧗ (List a) → (List a) → (List a) # maps a function returning list of list and concatenates concat-map concat ∘∘ map ⧗ (a → (List b)) → (List a) → (List b) -:test (concat-map [-0 : {}0] ((+1) : {}(+2))) ((-1) : ((+1) : ((-2) : {}(+2)))) +…<++>… concat-map + +:test ([-0 : {}0] <++> ((+1) : {}(+2))) ((-1) : ((+1) : ((-2) : {}(+2)))) # zips two lists discarding excess elements zip z [[[rec]]] ⧗ (List a) → (List b) → (List (Pair a b)) @@ -314,13 +317,13 @@ drop-while z [[[rec]]] ⧗ (a → Boolean) → (List a) → (List a) :test (drop-while zero? ((+0) : ((+0) : {}(+1)))) ({}(+1)) # returns all combinations of two lists -cross [[concat-map [map [1 : 0] 1] 1]] ⧗ (List a) → (List b) → (List (Pair a b)) +cross [[[[1 : 0] <$> 1] <++> 1]] ⧗ (List a) → (List b) → (List (Pair a b)) :test (cross "ab" "cd") (('a' : 'c') : (('a' : 'd') : (('b' : 'c') : {}('b' : 'd')))) # returns all combinations of three lists # TODO: add/use triple type (list element types can be different) -cross3 [[[concat-map [concat-map [map [2 : (1 : {}0)] 2] 2] 2]]] ⧗ (List a) → (List a) → (List a) → (List (List a)) +cross3 [[[[[[2 : (1 : {}0)] <$> 2] <++> 2] <++> 2]]] ⧗ (List a) → (List a) → (List a) → (List (List a)) # :test (cross "ab" "cd") (('a' : 'c') : (('a' : 'd') : (('b' : 'c') : {}('b' : 'd')))) |