Skip to content

Commit

Permalink
Minor improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
marvinborner committed Nov 6, 2024
1 parent 8dbf9ed commit 3f149e2
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
2 changes: 1 addition & 1 deletion std/Number/Unary.bruijn
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ uid [[[extract (2 inc init)]]] ⧗ Unary → Unary
:test (uid (+5u)) ((+5u))

# returns true if a unary number is zero
zero? [0 [(+0u)] true] ⧗ Unary → Boolean
zero? [0 [false] true] ⧗ Unary → Boolean

=?‣ zero?

Expand Down
9 changes: 9 additions & 0 deletions std/Option.bruijn
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,12 @@ result-or [[0 [[0 3]] [[[1 2]]]]]

:test (result-or "fail" none) ([[0 "fail"]])
:test (result-or "fail" (some "ok")) ([[1 "ok"]])

pure some ⧗ a → (Option a)

bind [[1 1 0]] ⧗ (Option a) → (a → (Option b)) → (Option a)

…>>=… bind

:test (none >>= (pure "idk")) (none)
:test ((some 'a') >>= [pure [1]]) (some ['a'])
10 changes: 10 additions & 0 deletions std/Result.bruijn
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# MIT License, Copyright (c) 2022 Marvin Borner
# TODO: the type signatures are wrong :)

:import std/Combinator .
:import std/Logic .
Expand Down Expand Up @@ -61,3 +62,12 @@ apply [[1 0 err]] ⧗ (Result a) → (a → b) → (Result b)

:test (apply (err [[0]]) [ok ([[1]] 0)]) (err [[0]])
:test (apply (ok [[0]]) [ok ([[1]] 0)]) (ok [[[0]]])

pure ok ⧗ a → (Result a)

bind [[1 0 err]] ⧗ (Result a) → (a → (Result b)) → (Result a)

…>>=… bind

:test ((err 'a') >>= (pure "idk")) (err 'a')
:test ((ok 'a') >>= [pure [1]]) (ok ['a'])

0 comments on commit 3f149e2

Please sign in to comment.