Fix module formatting

This commit is contained in:
Sam Mohr 2025-01-05 21:04:58 -08:00
parent cd0e2a4474
commit f524d35114
No known key found for this signature in database
GPG key ID: EA41D161A3C1BC99
4 changed files with 146 additions and 122 deletions

View file

@ -34,15 +34,15 @@ Eq implements
## `Bool` implements the `Eq` ability.
Bool := [True, False] implements [Eq { is_eq: bool_is_eq }]
bool_is_eq = \@Bool b1, @Bool b2 -> structural_eq b1 b2
bool_is_eq = \@Bool(b1), @Bool(b2) -> structural_eq(b1, b2)
## The boolean true value.
true : Bool
true = @Bool (True)
true = @Bool(True)
## The boolean false value.
false : Bool
false = @Bool (False)
false = @Bool(False)
## Returns `Bool.true` when both inputs are `Bool.true`. This is equivalent to
## the logic [AND](https://en.wikipedia.org/wiki/Logical_conjunction)

View file

@ -158,10 +158,10 @@ from_bytes = \bytes, fmt ->
{ result, rest } ->
if List.is_empty(rest) then
when result is
Ok val -> Ok (val)
Err TooShort -> Err (TooShort)
Ok(val) -> Ok(val)
Err(TooShort) -> Err(TooShort)
else
Err (Leftover (rest))
Err(Leftover(rest))
## Transform the `val` of a [DecodeResult]
map_result : DecodeResult a, (a -> b) -> DecodeResult b

View file

@ -84,7 +84,7 @@ custom : (f -> f) -> Inspector f where f implements InspectFormatter
custom = \fn -> @Inspector(fn)
apply : Inspector f, f -> f where f implements InspectFormatter
apply = \@Inspector fn, fmt -> fn(fmt)
apply = \@Inspector(fn), fmt -> fn(fmt)
Inspect implements
to_inspector : val -> Inspector f where val implements Inspect, f implements InspectFormatter
@ -138,140 +138,143 @@ dbg_init = \{} -> @DbgFormatter({ data: "" })
dbg_list : list, ElemWalker (DbgFormatter, Bool) list elem, (elem -> Inspector DbgFormatter) -> Inspector DbgFormatter
dbg_list = \content, walk_fn, to_dbg_inspector ->
custom(\f0 ->
dbg_write(f0, "[")
|> \f1 ->
walk_fn(
content,
(f1, Bool.false),
\(f2, prepend_sep), elem ->
f3 =
if prepend_sep then
dbg_write(f2, ", ")
else
f2
custom_list_dbg = \f0 ->
f1 = dbg_write(f0, "[")
(f5, _) = walk_fn(
content,
(f1, Bool.false),
\(f2, prepend_sep), elem ->
f3 =
if prepend_sep then
dbg_write(f2, ", ")
else
f2
elem
|> to_dbg_inspector
|> apply(f3)
|> \f4 -> (f4, Bool.true),
)
|> .0
|> dbg_write("]")
)
elem
|> to_dbg_inspector
|> apply(f3)
|> \f4 -> (f4, Bool.true),
)
dbg_write(f5, "]")
custom(custom_list_dbg)
dbg_set : set, ElemWalker (DbgFormatter, Bool) set elem, (elem -> Inspector DbgFormatter) -> Inspector DbgFormatter
dbg_set = \content, walk_fn, to_dbg_inspector ->
custom(\f0 ->
dbg_write(f0, "{")
|> \f1 ->
walk_fn(
content,
(f1, Bool.false),
\(f2, prepend_sep), elem ->
f3 =
if prepend_sep then
dbg_write(f2, ", ")
else
f2
custom_dbg_set = \f0 ->
f1 = dbg_write(f0, "{")
(f5, _) = walk_fn(
content,
(f1, Bool.false),
\(f2, prepend_sep), elem ->
f3 =
if prepend_sep then
dbg_write(f2, ", ")
else
f2
elem
|> to_dbg_inspector
|> apply(f3)
|> \f4 -> (f4, Bool.true),
)
|> .0
|> dbg_write("}")
)
elem
|> to_dbg_inspector
|> apply(f3)
|> \f4 -> (f4, Bool.true),
)
dbg_write(f5, "}")
custom(custom_dbg_set)
dbg_dict : dict, KeyValWalker (DbgFormatter, Bool) dict key value, (key -> Inspector DbgFormatter), (value -> Inspector DbgFormatter) -> Inspector DbgFormatter
dbg_dict = \d, walk_fn, key_to_inspector, value_to_inspector ->
custom(\f0 ->
dbg_write(f0, "{")
|> \f1 ->
walk_fn(
d,
(f1, Bool.false),
\(f2, prepend_sep), key, value ->
f3 =
if prepend_sep then
dbg_write(f2, ", ")
else
f2
custom_dbg_dict = \f0 ->
f1 = dbg_write(f0, "{")
(f5, _) = walk_fn(
d,
(f1, Bool.false),
\(f2, prepend_sep), key, value ->
f3 =
if prepend_sep then
dbg_write(f2, ", ")
else
f2
apply(key_to_inspector(key), f3)
|> dbg_write(": ")
|> \x -> apply(value_to_inspector(value), x)
|> \f4 -> (f4, Bool.true),
)
|> .0
|> dbg_write("}")
)
apply(key_to_inspector(key), f3)
|> dbg_write(": ")
|> \x -> apply(value_to_inspector(value), x)
|> \f4 -> (f4, Bool.true),
)
dbg_write(f5, "}")
custom(custom_dbg_dict)
dbg_tag : Str, List (Inspector DbgFormatter) -> Inspector DbgFormatter
dbg_tag = \name, fields ->
if List.is_empty(fields) then
custom(\f0 -> dbg_write(f0, name))
else
custom(\f0 ->
dbg_write(f0, "(")
|> dbg_write(name)
|> \f1 ->
List.walk(
fields,
f1,
\f2, inspector ->
dbg_write(f2, " ")
|> \x -> apply(inspector, x),
)
|> dbg_write(")")
)
custom_dbg_tag = \f0 ->
f1 =
dbg_write(f0, "(")
|> dbg_write(name)
f3 = List.walk(
fields,
f1,
\f2, inspector ->
dbg_write(f2, " ")
|> \x -> apply(inspector, x),
)
dbg_write(f3, ")")
custom(custom_dbg_tag)
dbg_tuple : List (Inspector DbgFormatter) -> Inspector DbgFormatter
dbg_tuple = \fields ->
custom(\f0 ->
dbg_write(f0, "(")
|> \f1 ->
List.walk(
fields,
(f1, Bool.false),
\(f2, prepend_sep), inspector ->
f3 =
if prepend_sep then
dbg_write(f2, ", ")
else
f2
custom_dbg_tuple = \f0 ->
f1 = dbg_write(f0, "(")
(f5, _) = List.walk(
fields,
(f1, Bool.false),
\(f2, prepend_sep), inspector ->
f3 =
if prepend_sep then
dbg_write(f2, ", ")
else
f2
apply(inspector, f3)
|> \f4 -> (f4, Bool.true),
)
|> .0
|> dbg_write(")")
)
apply(inspector, f3)
|> \f4 -> (f4, Bool.true),
)
dbg_write(f5, ")")
custom(custom_dbg_tuple)
dbg_record : List { key : Str, value : Inspector DbgFormatter } -> Inspector DbgFormatter
dbg_record = \fields ->
custom(\f0 ->
dbg_write(f0, "{")
|> \f1 ->
List.walk(
fields,
(f1, Bool.false),
\(f2, prepend_sep), { key, value } ->
f3 =
if prepend_sep then
dbg_write(f2, ", ")
else
f2
custom_dbg_record = \f0 ->
f1 = dbg_write(f0, "{")
(f5, _) = List.walk(
fields,
(f1, Bool.false),
\(f2, prepend_sep), { key, value } ->
f3 =
if prepend_sep then
dbg_write(f2, ", ")
else
f2
dbg_write(f3, key)
|> dbg_write(": ")
|> \x -> apply(value, x)
|> \f4 -> (f4, Bool.true),
)
|> .0
|> dbg_write("}")
)
dbg_write(f3, key)
|> dbg_write(": ")
|> \x -> apply(value, x)
|> \f4 -> (f4, Bool.true),
)
dbg_write(f5, "}")
custom(custom_dbg_record)
dbg_bool : Bool -> Inspector DbgFormatter
dbg_bool = \b ->
@ -280,12 +283,13 @@ dbg_bool = \b ->
dbg_str : Str -> Inspector DbgFormatter
dbg_str = \s ->
custom(\f0 ->
custom_dbg_str = \f0 ->
f0
|> dbg_write("\"")
|> dbg_write(s) # TODO: Should we be escaping strings for dbg/logging?
|> dbg_write("\"")
)
custom(custom_dbg_str)
dbg_opaque : * -> Inspector DbgFormatter
dbg_opaque = \_ ->