mirror of
https://github.com/roc-lang/roc.git
synced 2025-08-04 12:18:19 +00:00
More progress
This commit is contained in:
parent
b56fbd38e1
commit
0edbf16d55
79 changed files with 1351 additions and 1419 deletions
|
@ -116,14 +116,17 @@ is_eq = \xs, ys ->
|
|||
if len(xs) != len(ys) then
|
||||
Bool.false
|
||||
else
|
||||
walk_until(xs, Bool.true, (\_, k, x_val ->
|
||||
when get(ys, k) is
|
||||
Ok y_val if y_val == x_val ->
|
||||
Continue Bool.true
|
||||
walk_until(
|
||||
xs,
|
||||
Bool.true,
|
||||
\_, k, x_val ->
|
||||
when get(ys, k) is
|
||||
Ok(y_val) if y_val == x_val ->
|
||||
Continue(Bool.true)
|
||||
|
||||
_ ->
|
||||
Break Bool.false
|
||||
))
|
||||
_ ->
|
||||
Break(Bool.false),
|
||||
)
|
||||
|
||||
hash_dict : hasher, Dict k v -> hasher where v implements Hash, hasher implements Hasher
|
||||
hash_dict = \hasher, dict -> Hash.hash_unordered(hasher, to_list(dict), List.walk)
|
||||
|
@ -157,7 +160,7 @@ with_capacity = \requested ->
|
|||
|
||||
## Enlarge the dictionary for at least capacity additional elements
|
||||
reserve : Dict k v, U64 -> Dict k v
|
||||
reserve = \@Dict { buckets, data, max_bucket_capacity: original_max_bucket_capacity, max_load_factor, shifts }, requested ->
|
||||
reserve = \@Dict({ buckets, data, max_bucket_capacity: original_max_bucket_capacity, max_load_factor, shifts }), requested ->
|
||||
current_size = List.len(data)
|
||||
requested_size = Num.add_wrap(current_size, requested)
|
||||
size = Num.min(requested_size, max_size)
|
||||
|
@ -180,7 +183,7 @@ reserve = \@Dict { buckets, data, max_bucket_capacity: original_max_bucket_capac
|
|||
## This function will require regenerating the metadata if the size changes.
|
||||
## There will still be some overhead due to dictionary metadata always being a power of 2.
|
||||
release_excess_capacity : Dict k v -> Dict k v
|
||||
release_excess_capacity = \@Dict { buckets, data, max_bucket_capacity: original_max_bucket_capacity, max_load_factor, shifts } ->
|
||||
release_excess_capacity = \@Dict({ buckets, data, max_bucket_capacity: original_max_bucket_capacity, max_load_factor, shifts }) ->
|
||||
size = List.len(data)
|
||||
|
||||
# NOTE: If we want, we technically could increase the load factor here to potentially minimize size more.
|
||||
|
@ -237,7 +240,7 @@ single = \k, v ->
|
|||
## with the same capacity of the list and walk it calling [Dict.insert]
|
||||
from_list : List (k, v) -> Dict k v
|
||||
from_list = \data ->
|
||||
List.walk(data, empty({}), (\dict, (k, v) -> insert(dict, k, v)))
|
||||
List.walk(data, empty({}), \dict, (k, v) -> insert(dict, k, v))
|
||||
|
||||
## Returns the number of values in the dictionary.
|
||||
## ```roc
|
||||
|
@ -250,7 +253,7 @@ from_list = \data ->
|
|||
## |> Bool.is_eq(3)
|
||||
## ```
|
||||
len : Dict * * -> U64
|
||||
len = \@Dict { data } ->
|
||||
len = \@Dict({ data }) ->
|
||||
List.len(data)
|
||||
|
||||
## Check if the dictionary is empty.
|
||||
|
@ -278,7 +281,7 @@ is_empty = \@Dict({ data }) ->
|
|||
clear : Dict k v -> Dict k v
|
||||
clear = \@Dict({ buckets, data, max_bucket_capacity, max_load_factor, shifts }) ->
|
||||
@Dict({
|
||||
buckets: List.map(buckets, (\_ -> empty_bucket)),
|
||||
buckets: List.map(buckets, \_ -> empty_bucket),
|
||||
# use take_first to keep around the capacity
|
||||
data: List.take_first(data, 0),
|
||||
max_bucket_capacity,
|
||||
|
@ -293,9 +296,12 @@ map : Dict k a, (k, a -> b) -> Dict k b
|
|||
map = \dict, transform ->
|
||||
init = with_capacity(capacity(dict))
|
||||
|
||||
walk(dict, init, (\answer, k, v ->
|
||||
insert(answer, k, transform(k, v))
|
||||
))
|
||||
walk(
|
||||
dict,
|
||||
init,
|
||||
\answer, k, v ->
|
||||
insert(answer, k, transform(k, v)),
|
||||
)
|
||||
|
||||
## Like [Dict.map], except the transformation function wraps the return value
|
||||
## in a dictionary. At the end, all the dictionaries get joined together
|
||||
|
@ -306,9 +312,12 @@ join_map : Dict a b, (a, b -> Dict x y) -> Dict x y
|
|||
join_map = \dict, transform ->
|
||||
init = with_capacity(capacity(dict)) # Might be a pessimization
|
||||
|
||||
walk(dict, init, (\answer, k, v ->
|
||||
insert_all(answer, transform(k, v))
|
||||
))
|
||||
walk(
|
||||
dict,
|
||||
init,
|
||||
\answer, k, v ->
|
||||
insert_all(answer, transform(k, v)),
|
||||
)
|
||||
|
||||
## Iterate through the keys and values in the dictionary and call the provided
|
||||
## function with signature `state, k, v -> state` for each value, with an
|
||||
|
@ -323,7 +332,7 @@ join_map = \dict, transform ->
|
|||
## ```
|
||||
walk : Dict k v, state, (state, k, v -> state) -> state
|
||||
walk = \@Dict({ data }), initial_state, transform ->
|
||||
List.walk(data, initial_state, (\state, (k, v) -> transform(state, k, v)))
|
||||
List.walk(data, initial_state, \state, (k, v) -> transform(state, k, v))
|
||||
|
||||
## Same as [Dict.walk], except you can stop walking early.
|
||||
##
|
||||
|
@ -355,7 +364,7 @@ walk = \@Dict({ data }), initial_state, transform ->
|
|||
## ```
|
||||
walk_until : Dict k v, state, (state, k, v -> [Continue state, Break state]) -> state
|
||||
walk_until = \@Dict({ data }), initial_state, transform ->
|
||||
List.walk_until(data, initial_state, (\state, (k, v) -> transform(state, k, v)))
|
||||
List.walk_until(data, initial_state, \state, (k, v) -> transform(state, k, v))
|
||||
|
||||
## Run the given function on each key-value pair of a dictionary, and return
|
||||
## a dictionary with just the pairs for which the function returned `Bool.true`.
|
||||
|
@ -396,7 +405,7 @@ keep_if_help = \@Dict(dict), predicate, index, length ->
|
|||
## ```
|
||||
drop_if : Dict k v, ((k, v) -> Bool) -> Dict k v
|
||||
drop_if = \dict, predicate ->
|
||||
Dict.keep_if(dict, (\e -> Bool.not(predicate(e))))
|
||||
Dict.keep_if(dict, \e -> Bool.not(predicate(e)))
|
||||
|
||||
## Get the value for a given key. If there is a value for the specified key it
|
||||
## will return [Ok value], otherwise return [Err KeyNotFound].
|
||||
|
@ -527,7 +536,7 @@ update : Dict k v, k, (Result v [Missing] -> Result v [Missing]) -> Dict k v
|
|||
update = \@Dict({ buckets, data, max_bucket_capacity, max_load_factor, shifts }), key, alter ->
|
||||
{ bucket_index, result } = find(@Dict({ buckets, data, max_bucket_capacity, max_load_factor, shifts }), key)
|
||||
when result is
|
||||
Ok value ->
|
||||
Ok(value) ->
|
||||
when alter(Ok(value)) is
|
||||
Ok(new_value) ->
|
||||
bucket = list_get_unsafe(buckets, bucket_index)
|
||||
|
@ -537,7 +546,7 @@ update = \@Dict({ buckets, data, max_bucket_capacity, max_load_factor, shifts })
|
|||
Err(Missing) ->
|
||||
remove_bucket(@Dict({ buckets, data, max_bucket_capacity, max_load_factor, shifts }), bucket_index)
|
||||
|
||||
Err KeyNotFound ->
|
||||
Err(KeyNotFound) ->
|
||||
when alter(Err(Missing)) is
|
||||
Ok(new_value) ->
|
||||
if List.len(data) >= max_bucket_capacity then
|
||||
|
@ -601,7 +610,7 @@ to_list = \@Dict({ data }) ->
|
|||
## ```
|
||||
keys : Dict k v -> List k
|
||||
keys = \@Dict({ data }) ->
|
||||
List.map(data, (\(k, _) -> k))
|
||||
List.map(data, \(k, _) -> k)
|
||||
|
||||
## Returns the values of a dictionary as a [List].
|
||||
## This requires allocating a temporary [List], prefer using [Dict.to_list] or [Dict.walk] instead.
|
||||
|
@ -616,7 +625,7 @@ keys = \@Dict({ data }) ->
|
|||
## ```
|
||||
values : Dict k v -> List v
|
||||
values = \@Dict({ data }) ->
|
||||
List.map(data, (\(_, v) -> v))
|
||||
List.map(data, \(_, v) -> v)
|
||||
|
||||
## Combine two dictionaries by keeping the [union](https://en.wikipedia.org/wiki/Union_(set_theory))
|
||||
## of all the key-value pairs. This means that all the key-value pairs in
|
||||
|
@ -678,14 +687,17 @@ keep_shared = \xs0, ys0 ->
|
|||
else
|
||||
(xs0, ys0)
|
||||
|
||||
walk(xs1, with_capacity(len(xs1)), (\state, k, v ->
|
||||
when get(ys1, k) is
|
||||
Ok(yv) if v == yv ->
|
||||
insert(state, k, v)
|
||||
walk(
|
||||
xs1,
|
||||
with_capacity(len(xs1)),
|
||||
\state, k, v ->
|
||||
when get(ys1, k) is
|
||||
Ok(yv) if v == yv ->
|
||||
insert(state, k, v)
|
||||
|
||||
_ ->
|
||||
state
|
||||
))
|
||||
_ ->
|
||||
state,
|
||||
)
|
||||
|
||||
## Remove the key-value pairs in the first input that are also in the second
|
||||
## using the [set difference](https://en.wikipedia.org/wiki/Complement_(set_theory)#Relative_complement)
|
||||
|
@ -709,7 +721,7 @@ keep_shared = \xs0, ys0 ->
|
|||
## ```
|
||||
remove_all : Dict k v, Dict k v -> Dict k v
|
||||
remove_all = \xs, ys ->
|
||||
walk(ys, xs, (\state, k, _ -> remove(state, k)))
|
||||
walk(ys, xs, \state, k, _ -> remove(state, k))
|
||||
|
||||
# Below here is a list of generic helpers and internal data types for Dict
|
||||
Bucket : {
|
||||
|
@ -896,10 +908,13 @@ calc_num_buckets = \shifts ->
|
|||
Num.min(Num.shift_left_by(1, Num.sub_wrap(64, shifts)), max_bucket_count)
|
||||
|
||||
fill_buckets_from_data = \buckets0, data, shifts ->
|
||||
List.walk_with_index(data, buckets0, (\buckets1, (key, _), data_index ->
|
||||
(bucket_index, dist_and_fingerprint) = next_while_less(buckets1, key, shifts)
|
||||
place_and_shift_up(buckets1, { dist_and_fingerprint, data_index: Num.to_u32(data_index) }, bucket_index)
|
||||
))
|
||||
List.walk_with_index(
|
||||
data,
|
||||
buckets0,
|
||||
\buckets1, (key, _), data_index ->
|
||||
(bucket_index, dist_and_fingerprint) = next_while_less(buckets1, key, shifts)
|
||||
place_and_shift_up(buckets1, { dist_and_fingerprint, data_index: Num.to_u32(data_index) }, bucket_index),
|
||||
)
|
||||
|
||||
next_while_less : List Bucket, k, U8 -> (U64, U32) where k implements Hash & Eq
|
||||
next_while_less = \buckets, key, shifts ->
|
||||
|
@ -1056,7 +1071,7 @@ expect
|
|||
|> insert("bar", {})
|
||||
|> insert("baz", {})
|
||||
|
||||
contains(dict, "baz") && !contains(dict, "other")
|
||||
contains(dict, "baz") && !(contains(dict, "other"))
|
||||
|
||||
expect
|
||||
dict =
|
||||
|
@ -1216,18 +1231,27 @@ expect
|
|||
]
|
||||
|
||||
dict =
|
||||
List.walk(bad_keys, Dict.empty({}), (\acc, k ->
|
||||
Dict.update(acc, k, (\val ->
|
||||
when val is
|
||||
Ok(p) -> Ok(Num.add_wrap(p, 1))
|
||||
Err(Missing) -> Ok(0)
|
||||
))
|
||||
))
|
||||
List.walk(
|
||||
bad_keys,
|
||||
Dict.empty({}),
|
||||
\acc, k ->
|
||||
Dict.update(
|
||||
acc,
|
||||
k,
|
||||
\val ->
|
||||
when val is
|
||||
Ok(p) -> Ok(Num.add_wrap(p, 1))
|
||||
Err(Missing) -> Ok(0),
|
||||
),
|
||||
)
|
||||
|
||||
all_inserted_correctly =
|
||||
List.walk(bad_keys, Bool.true, (\acc, k ->
|
||||
acc && Dict.contains(dict, k)
|
||||
))
|
||||
List.walk(
|
||||
bad_keys,
|
||||
Bool.true,
|
||||
\acc, k ->
|
||||
acc && Dict.contains(dict, k),
|
||||
)
|
||||
|
||||
all_inserted_correctly
|
||||
|
||||
|
@ -1324,10 +1348,10 @@ add_u32 = \@LowLevelHasher({ initialized_seed, state }), u32 ->
|
|||
combine_state(@LowLevelHasher({ initialized_seed, state }), { a, b: a, seed: initialized_seed, length: 4 })
|
||||
|
||||
add_u64 = \@LowLevelHasher({ initialized_seed, state }), u64 ->
|
||||
p0 = Num.bitwise_and 0xFFFF_FFFF u64
|
||||
p1 = Num.shift_right_zf_by u64 32
|
||||
a = Num.shift_left_by p0 32 |> Num.bitwise_or p1
|
||||
b = Num.shift_left_by p1 32 |> Num.bitwise_or p0
|
||||
p0 = Num.bitwise_and(0xFFFF_FFFF, u64)
|
||||
p1 = Num.shift_right_zf_by(u64, 32)
|
||||
a = Num.shift_left_by(p0, 32) |> Num.bitwise_or(p1)
|
||||
b = Num.shift_left_by(p1, 32) |> Num.bitwise_or(p0)
|
||||
|
||||
combine_state(@LowLevelHasher({ initialized_seed, state }), { a, b, seed: initialized_seed, length: 8 })
|
||||
|
||||
|
@ -1370,36 +1394,33 @@ add_bytes = \@LowLevelHasher({ initialized_seed, state }), list ->
|
|||
|
||||
hash_bytes_helper48 : U64, U64, U64, List U8, U64, U64 -> { a : U64, b : U64, seed : U64 }
|
||||
hash_bytes_helper48 = \seed, see1, see2, list, index, remaining ->
|
||||
# TODO: update!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||
new_seed = wymix (Num.bitwise_xor (wyr8 list index) wyp1) (Num.bitwise_xor (wyr8 list (Num.add_wrap index 8)) seed)
|
||||
new_see1 = wymix (Num.bitwise_xor (wyr8 list (Num.add_wrap index 16)) wyp2) (Num.bitwise_xor (wyr8 list (Num.add_wrap index 24)) see1)
|
||||
new_see2 = wymix (Num.bitwise_xor (wyr8 list (Num.add_wrap index 32)) wyp3) (Num.bitwise_xor (wyr8 list (Num.add_wrap index 40)) see2)
|
||||
new_remaining = Num.sub_wrap remaining 48
|
||||
new_index = Num.add_wrap index 48
|
||||
new_seed = wymix(Num.bitwise_xor(wyr8(list, index), wyp1), Num.bitwise_xor(wyr8(list, Num.add_wrap(index, 8)), seed))
|
||||
new_see1 = wymix(Num.bitwise_xor(wyr8(list, Num.add_wrap(index, 16)), wyp2), Num.bitwise_xor(wyr8(list, Num.add_wrap(index, 24)), see1))
|
||||
new_see2 = wymix(Num.bitwise_xor(wyr8(list, Num.add_wrap(index, 32)), wyp3), Num.bitwise_xor(wyr8(list, Num.add_wrap(index, 40)), see2))
|
||||
new_remaining = Num.sub_wrap(remaining, 48)
|
||||
new_index = Num.add_wrap(index, 48)
|
||||
|
||||
if new_remaining > 48 then
|
||||
hash_bytes_helper48 new_seed new_see1 new_see2 list new_index new_remaining
|
||||
hash_bytes_helper48(new_seed, new_see1, new_see2, list, new_index, new_remaining)
|
||||
else if new_remaining > 16 then
|
||||
final_seed = Num.bitwise_xor new_see2 (Num.bitwise_xor new_see1 new_seed)
|
||||
final_seed = Num.bitwise_xor(new_see2, Num.bitwise_xor(new_see1, new_seed))
|
||||
|
||||
hash_bytes_helper16 final_seed list new_index new_remaining
|
||||
hash_bytes_helper16(final_seed, list, new_index, new_remaining)
|
||||
else
|
||||
final_seed = Num.bitwise_xor new_see2 (Num.bitwise_xor new_see1 new_seed)
|
||||
final_seed = Num.bitwise_xor(new_see2, Num.bitwise_xor(new_see1, new_seed))
|
||||
|
||||
{ a: wyr8 list (Num.sub_wrap new_remaining 16 |> Num.add_wrap new_index), b: wyr8 list (Num.sub_wrap new_remaining 8 |> Num.add_wrap new_index), seed: final_seed }
|
||||
{ a: wyr8(list, (Num.sub_wrap(new_remaining, 16) |> Num.add_wrap(new_index))), b: wyr8(list, (Num.sub_wrap(new_remaining, 8) |> Num.add_wrap(new_index))), seed: final_seed }
|
||||
|
||||
hash_bytes_helper16 : U64, List U8, U64, U64 -> { a : U64, b : U64, seed : U64 }
|
||||
hash_bytes_helper16 = \seed, list, index, remaining ->
|
||||
new_seed = wymix (Num.bitwise_xor (wyr8 list index) wyp1) (Num.bitwise_xor (wyr8 list (Num.add_wrap index 8)) seed)
|
||||
new_remaining = Num.sub_wrap remaining 16
|
||||
new_index = Num.add_wrap index 16
|
||||
new_seed = wymix(Num.bitwise_xor(wyr8(list, index), wyp1), Num.bitwise_xor(wyr8(list, Num.add_wrap(index, 8)), seed))
|
||||
new_remaining = Num.sub_wrap(remaining, 16)
|
||||
new_index = Num.add_wrap(index, 16)
|
||||
|
||||
if new_remaining <= 16 then
|
||||
{ a: wyr8 list (Num.sub_wrap new_remaining 16 |> Num.add_wrap new_index), b: wyr8 list (Num.sub_wrap new_remaining 8 |> Num.add_wrap new_index), seed: new_seed }
|
||||
{ a: wyr8(list, (Num.sub_wrap(new_remaining, 16) |> Num.add_wrap(new_index))), b: wyr8(list, (Num.sub_wrap(new_remaining, 8) |> Num.add_wrap(new_index))), seed: new_seed }
|
||||
else
|
||||
hash_bytes_helper16 new_seed list new_index new_remaining
|
||||
|
||||
# !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||
hash_bytes_helper16(new_seed, list, new_index, new_remaining)
|
||||
|
||||
wyp0 : U64
|
||||
wyp0 = 0xa0761d6478bd642f
|
||||
|
@ -1667,7 +1688,7 @@ expect
|
|||
|> Dict.insert("Alice", 17)
|
||||
|> Dict.insert("Bob", 18)
|
||||
|> Dict.insert("Charlie", 19)
|
||||
|> Dict.walk_until(Bool.false, (\_, _, age -> if age >= 18 then Break(Bool.true) else Continue(Bool.false)))
|
||||
|> Dict.walk_until(Bool.false, \_, _, age -> if age >= 18 then Break(Bool.true) else Continue(Bool.false))
|
||||
|> Bool.is_eq(Bool.true)
|
||||
|
||||
expect
|
||||
|
@ -1709,7 +1730,7 @@ expect
|
|||
|> Dict.insert(2, 2)
|
||||
|> Dict.insert(3, 3)
|
||||
|> Dict.insert(4, 4)
|
||||
|> Dict.keep_if(\(k, _v) -> !List.contains(keys_to_delete, k))
|
||||
|> Dict.keep_if(\(k, _v) -> !(List.contains(keys_to_delete, k)))
|
||||
|
||||
d2 =
|
||||
Dict.empty({})
|
||||
|
@ -1728,7 +1749,7 @@ expect
|
|||
|> Dict.insert(2, 2)
|
||||
|> Dict.insert(3, 3)
|
||||
|> Dict.insert(4, 4)
|
||||
|> Dict.keep_if(\(k, _v) -> !List.contains(keys_to_delete, k))
|
||||
|> Dict.keep_if(\(k, _v) -> !(List.contains(keys_to_delete, k)))
|
||||
|
||||
d2 =
|
||||
Dict.empty({})
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -1,111 +1,99 @@
|
|||
interface AStar
|
||||
exposes [initialModel, reconstructPath, updateCost, cheapestOpen, astar, findPath]
|
||||
imports []
|
||||
|
||||
module [initial_model, reconstruct_path, update_cost, cheapest_open, astar, find_path]
|
||||
|
||||
# a port of https://github.com/krisajenkins/elm-astar/blob/2.1.3/src/AStar/Generalised.elm
|
||||
|
||||
Model position :
|
||||
{ evaluated : Set position
|
||||
, openSet : Set position
|
||||
, costs : Map.Map position F64
|
||||
, cameFrom : Map.Map position position
|
||||
}
|
||||
Model position : {
|
||||
evaluated : Set position,
|
||||
open_set : Set position,
|
||||
costs : Map.Map position F64,
|
||||
came_from : Map.Map position position,
|
||||
}
|
||||
|
||||
initial_model : position -> Model position
|
||||
initial_model = \start -> {
|
||||
evaluated: Set.empty({}),
|
||||
open_set: Set.single(start),
|
||||
costs: Dict.single(start, 0.0),
|
||||
came_from: Map.empty,
|
||||
}
|
||||
|
||||
initialModel : position -> Model position
|
||||
initialModel = \start ->
|
||||
{ evaluated : Set.empty {}
|
||||
, openSet : Set.single start
|
||||
, costs : Dict.single start 0.0
|
||||
, cameFrom : Map.empty
|
||||
}
|
||||
cheapest_open : (position -> F64), Model position -> Result position [KeyNotFound]*
|
||||
cheapest_open = \cost_function, model ->
|
||||
|
||||
folder = \res_smallest_so_far, position ->
|
||||
when Map.get(model.costs, position) is
|
||||
Err(e) ->
|
||||
Err(e)
|
||||
|
||||
cheapestOpen : (position -> F64), Model position -> Result position [KeyNotFound]*
|
||||
cheapestOpen = \costFunction, model ->
|
||||
Ok(cost) ->
|
||||
position_cost = cost_function(position)
|
||||
|
||||
folder = \resSmallestSoFar, position ->
|
||||
when Map.get model.costs position is
|
||||
Err e ->
|
||||
Err e
|
||||
when res_smallest_so_far is
|
||||
Err(_) -> Ok({ position, cost: cost + position_cost })
|
||||
Ok(smallest_so_far) ->
|
||||
if position_cost + cost < smallest_so_far.cost then
|
||||
Ok({ position, cost: cost + position_cost })
|
||||
else
|
||||
Ok(smallest_so_far)
|
||||
|
||||
Ok cost ->
|
||||
positionCost = costFunction position
|
||||
Set.walk(model.open_set, Err(KeyNotFound), folder)
|
||||
|> Result.map(\x -> x.position)
|
||||
|
||||
when resSmallestSoFar is
|
||||
Err _ -> Ok { position, cost: cost + positionCost }
|
||||
Ok smallestSoFar ->
|
||||
if positionCost + cost < smallestSoFar.cost then
|
||||
Ok { position, cost: cost + positionCost }
|
||||
|
||||
else
|
||||
Ok smallestSoFar
|
||||
|
||||
Set.walk model.openSet (Err KeyNotFound) folder
|
||||
|> Result.map (\x -> x.position)
|
||||
|
||||
|
||||
|
||||
reconstructPath : Map position position, position -> List position
|
||||
reconstructPath = \cameFrom, goal ->
|
||||
when Map.get cameFrom goal is
|
||||
Err KeyNotFound ->
|
||||
reconstruct_path : Map position position, position -> List position
|
||||
reconstruct_path = \came_from, goal ->
|
||||
when Map.get(came_from, goal) is
|
||||
Err(KeyNotFound) ->
|
||||
[]
|
||||
|
||||
Ok next ->
|
||||
List.append (reconstructPath cameFrom next) goal
|
||||
Ok(next) ->
|
||||
List.append(reconstruct_path(came_from, next), goal)
|
||||
|
||||
updateCost : position, position, Model position -> Model position
|
||||
updateCost = \current, neighbour, model ->
|
||||
newCameFrom = Map.insert model.cameFrom neighbour current
|
||||
update_cost : position, position, Model position -> Model position
|
||||
update_cost = \current, neighbour, model ->
|
||||
new_came_from = Map.insert(model.came_from, neighbour, current)
|
||||
|
||||
newCosts = Map.insert model.costs neighbour distanceTo
|
||||
new_costs = Map.insert(model.costs, neighbour, distance_to)
|
||||
|
||||
distanceTo = reconstructPath newCameFrom neighbour
|
||||
|> List.len
|
||||
|> Num.toFrac
|
||||
distance_to =
|
||||
reconstruct_path(new_came_from, neighbour)
|
||||
|> List.len
|
||||
|> Num.to_frac
|
||||
|
||||
newModel = { model & costs : newCosts , cameFrom : newCameFrom }
|
||||
new_model = { model & costs: new_costs, came_from: new_came_from }
|
||||
|
||||
when Map.get model.costs neighbour is
|
||||
Err KeyNotFound ->
|
||||
newModel
|
||||
|
||||
Ok previousDistance ->
|
||||
if distanceTo < previousDistance then
|
||||
newModel
|
||||
when Map.get(model.costs, neighbour) is
|
||||
Err(KeyNotFound) ->
|
||||
new_model
|
||||
|
||||
Ok(previous_distance) ->
|
||||
if distance_to < previous_distance then
|
||||
new_model
|
||||
else
|
||||
model
|
||||
|
||||
|
||||
findPath : { costFunction: (position, position -> F64), moveFunction: (position -> Set position), start : position, end : position } -> Result (List position) [KeyNotFound]*
|
||||
findPath = \{ costFunction, moveFunction, start, end } ->
|
||||
astar costFunction moveFunction end (initialModel start)
|
||||
|
||||
find_path : { cost_function : position, position -> F64, move_function : position -> Set position, start : position, end : position } -> Result (List position) [KeyNotFound]*
|
||||
find_path = \{ cost_function, move_function, start, end } ->
|
||||
astar(cost_function, move_function, end, initial_model(start))
|
||||
|
||||
astar : (position, position -> F64), (position -> Set position), position, Model position -> [Err [KeyNotFound]*, Ok (List position)]*
|
||||
astar = \costFn, moveFn, goal, model ->
|
||||
when cheapestOpen (\position -> costFn goal position) model is
|
||||
Err _ ->
|
||||
Err KeyNotFound
|
||||
astar = \cost_fn, move_fn, goal, model ->
|
||||
when cheapest_open(\position -> cost_fn(goal, position), model) is
|
||||
Err(_) ->
|
||||
Err(KeyNotFound)
|
||||
|
||||
Ok current ->
|
||||
Ok(current) ->
|
||||
if current == goal then
|
||||
Ok (reconstructPath model.cameFrom goal)
|
||||
|
||||
Ok(reconstruct_path(model.came_from, goal))
|
||||
else
|
||||
model_popped = { model & open_set: Set.remove(model.open_set, current), evaluated: Set.insert(model.evaluated, current) }
|
||||
|
||||
modelPopped = { model & openSet : Set.remove model.openSet current, evaluated : Set.insert model.evaluated current }
|
||||
neighbours = move_fn(current)
|
||||
|
||||
neighbours = moveFn current
|
||||
new_neighbours = Set.difference(neighbours, model_popped.evaluated)
|
||||
|
||||
newNeighbours = Set.difference neighbours modelPopped.evaluated
|
||||
model_with_neighbours = { model_popped & open_set: Set.union(model_popped.open_set, new_neighbours) }
|
||||
|
||||
modelWithNeighbours = { modelPopped & openSet : Set.union modelPopped.openSet newNeighbours }
|
||||
model_with_costs = Set.walk(new_neighbours, model_with_neighbours, \md, nb -> update_cost(current, nb, md))
|
||||
|
||||
modelWithCosts = Set.walk newNeighbours modelWithNeighbours (\md, nb -> updateCost current nb md)
|
||||
|
||||
astar costFn moveFn goal modelWithCosts
|
||||
astar(cost_fn, move_fn, goal, model_with_costs)
|
||||
|
||||
|
|
|
@ -1,6 +1,4 @@
|
|||
interface Dep1
|
||||
exposes [three, str, Unit, Identity, one, two]
|
||||
imports []
|
||||
module [three, str, Unit, Identity, one, two]
|
||||
|
||||
import Dep3Blah exposing [foo]
|
||||
|
||||
|
|
|
@ -1,6 +1,4 @@
|
|||
interface Dep2
|
||||
exposes [one, two, blah]
|
||||
imports []
|
||||
module [one, two, blah]
|
||||
|
||||
import Dep3Blah exposing [foo, bar]
|
||||
|
||||
|
|
|
@ -1,6 +1,4 @@
|
|||
interface Dep3Blah
|
||||
exposes [one, two, foo, bar]
|
||||
imports []
|
||||
module [one, two, foo, bar]
|
||||
|
||||
import Dep3Other
|
||||
|
||||
|
|
|
@ -1,6 +1,4 @@
|
|||
interface Dep3Other
|
||||
exposes [foo, bar]
|
||||
imports []
|
||||
module [foo, bar]
|
||||
|
||||
foo = "foo from Dep3Other"
|
||||
bar = "bar from Dep3Other"
|
||||
|
|
|
@ -1,6 +1,4 @@
|
|||
interface ImportAlias
|
||||
exposes [unit]
|
||||
imports []
|
||||
module [unit]
|
||||
|
||||
import Dep1
|
||||
|
||||
|
|
|
@ -1,18 +1,16 @@
|
|||
interface ManualAttr
|
||||
exposes []
|
||||
imports []
|
||||
module []
|
||||
|
||||
# manually replicates the Attr wrapping that uniqueness inference uses, to try and find out why they are different
|
||||
# It is very important that there are no signatures here! elm uses an optimization that leads to less copying when
|
||||
# signatures are given.
|
||||
|
||||
map =
|
||||
unAttr = \Attr _ foobar -> foobar
|
||||
un_attr = \Attr(_, foobar) -> foobar
|
||||
|
||||
r = Attr unknown "bar"
|
||||
r = Attr(unknown, "bar")
|
||||
|
||||
s = Attr unknown2 { left : Attr Shared "foo" }
|
||||
s = Attr(unknown2, { left: Attr(Shared, "foo") })
|
||||
|
||||
when True is
|
||||
_ -> { y : r }
|
||||
_ -> { y : (unAttr s).left }
|
||||
_ -> { y: r }
|
||||
_ -> { y: (un_attr(s)).left }
|
||||
|
|
|
@ -1,6 +1,4 @@
|
|||
interface OneDep
|
||||
exposes [str]
|
||||
imports []
|
||||
module [str]
|
||||
|
||||
import Dep3Blah exposing [foo]
|
||||
|
||||
|
|
|
@ -1,6 +1,4 @@
|
|||
interface Primary
|
||||
exposes [blah2, blah3, str, alwaysThree, identity, z, w, succeed, withDefault, yay]
|
||||
imports []
|
||||
module [blah2, blah3, str, always_three, identity, z, w, succeed, with_default, yay]
|
||||
|
||||
import Dep1
|
||||
import Dep2
|
||||
|
@ -12,24 +10,24 @@ blah3 = bar
|
|||
|
||||
str = Dep1.str
|
||||
|
||||
alwaysThree = \_ -> Dep1.three
|
||||
always_three = \_ -> Dep1.three
|
||||
|
||||
identity = \a -> a
|
||||
|
||||
z = identity (alwaysThree {})
|
||||
z = identity(always_three({}))
|
||||
|
||||
w : Dep1.Identity {}
|
||||
w = Identity {}
|
||||
w = Identity({})
|
||||
|
||||
succeed : a -> Dep1.Identity a
|
||||
succeed = \x -> Identity x
|
||||
succeed = \x -> Identity(x)
|
||||
|
||||
withDefault = Res.withDefault
|
||||
with_default = Res.with_default
|
||||
|
||||
yay : Res.Res {} err
|
||||
yay =
|
||||
ok = Ok "foo"
|
||||
ok = Ok("foo")
|
||||
|
||||
f = \_ -> {}
|
||||
|
||||
Res.map ok f
|
||||
Res.map(ok, f)
|
||||
|
|
|
@ -1,49 +1,46 @@
|
|||
app "quicksort" provides [swap, partition, partitionHelp, quicksort] to "./platform"
|
||||
app [swap, partition, partition_help, quicksort] {}
|
||||
|
||||
quicksort : List (Num a), U64, U64 -> List (Num a)
|
||||
quicksort = \list, low, high ->
|
||||
when partition low high list is
|
||||
Pair partitionIndex partitioned ->
|
||||
when partition(low, high, list) is
|
||||
Pair(partition_index, partitioned) ->
|
||||
partitioned
|
||||
|> quicksort low (partitionIndex - 1)
|
||||
|> quicksort (partitionIndex + 1) high
|
||||
|
||||
|> quicksort(low, (partition_index - 1))
|
||||
|> quicksort((partition_index + 1), high)
|
||||
|
||||
swap : U64, U64, List a -> List a
|
||||
swap = \i, j, list ->
|
||||
when Pair (List.get list i) (List.get list j) is
|
||||
Pair (Ok atI) (Ok atJ) ->
|
||||
when Pair(List.get(list, i), List.get(list, j)) is
|
||||
Pair(Ok(at_i), Ok(at_j)) ->
|
||||
list
|
||||
|> List.set i atJ
|
||||
|> List.set j atI
|
||||
|> List.set(i, at_j)
|
||||
|> List.set(j, at_i)
|
||||
|
||||
_ ->
|
||||
[]
|
||||
|
||||
|
||||
partition : U64, U64, List (Num a) -> [Pair U64 (List (Num a))]
|
||||
partition = \low, high, initialList ->
|
||||
when List.get initialList high is
|
||||
Ok pivot ->
|
||||
when partitionHelp (low - 1) low initialList high pivot is
|
||||
Pair newI newList ->
|
||||
Pair (newI + 1) (swap (newI + 1) high newList)
|
||||
partition = \low, high, initial_list ->
|
||||
when List.get(initial_list, high) is
|
||||
Ok(pivot) ->
|
||||
when partition_help((low - 1), low, initial_list, high, pivot) is
|
||||
Pair(new_i, new_list) ->
|
||||
Pair((new_i + 1), swap((new_i + 1), high, new_list))
|
||||
|
||||
Err _ ->
|
||||
Pair (low - 1) initialList
|
||||
Err(_) ->
|
||||
Pair((low - 1), initial_list)
|
||||
|
||||
|
||||
partitionHelp : U64, U64, List (Num a), U64, (Num a) -> [Pair U64 (List (Num a))]
|
||||
partitionHelp = \i, j, list, high, pivot ->
|
||||
partition_help : U64, U64, List (Num a), U64, Num a -> [Pair U64 (List (Num a))]
|
||||
partition_help = \i, j, list, high, pivot ->
|
||||
if j < high then
|
||||
when List.get list j is
|
||||
Ok value ->
|
||||
when List.get(list, j) is
|
||||
Ok(value) ->
|
||||
if value <= pivot then
|
||||
partitionHelp (i + 1) (j + 1) (swap (i + 1) j list) high pivot
|
||||
partition_help((i + 1), (j + 1), swap((i + 1), j, list), high, pivot)
|
||||
else
|
||||
partitionHelp i (j + 1) list high pivot
|
||||
partition_help(i, (j + 1), list, high, pivot)
|
||||
|
||||
Err _ ->
|
||||
Pair i list
|
||||
Err(_) ->
|
||||
Pair(i, list)
|
||||
else
|
||||
Pair i list
|
||||
Pair(i, list)
|
||||
|
|
|
@ -1,57 +1,53 @@
|
|||
app "quicksort" provides [quicksort] to "./platform"
|
||||
app [quicksort] {}
|
||||
|
||||
quicksortHelp : List (Num a), U64, U64 -> List (Num a)
|
||||
quicksortHelp = \list, low, high ->
|
||||
quicksort_help : List (Num a), U64, U64 -> List (Num a)
|
||||
quicksort_help = \list, low, high ->
|
||||
if low < high then
|
||||
when partition low high list is
|
||||
Pair partitionIndex partitioned ->
|
||||
when partition(low, high, list) is
|
||||
Pair(partition_index, partitioned) ->
|
||||
partitioned
|
||||
|> quicksortHelp low (partitionIndex - 1)
|
||||
|> quicksortHelp (partitionIndex + 1) high
|
||||
|> quicksort_help(low, (partition_index - 1))
|
||||
|> quicksort_help((partition_index + 1), high)
|
||||
else
|
||||
list
|
||||
|
||||
|
||||
swap : U64, U64, List a -> List a
|
||||
swap = \i, j, list ->
|
||||
when Pair (List.get list i) (List.get list j) is
|
||||
Pair (Ok atI) (Ok atJ) ->
|
||||
when Pair(List.get(list, i), List.get(list, j)) is
|
||||
Pair(Ok(at_i), Ok(at_j)) ->
|
||||
list
|
||||
|> List.set i atJ
|
||||
|> List.set j atI
|
||||
|> List.set(i, at_j)
|
||||
|> List.set(j, at_i)
|
||||
|
||||
_ ->
|
||||
[]
|
||||
|
||||
partition : U64, U64, List (Num a) -> [Pair U64 (List (Num a))]
|
||||
partition = \low, high, initialList ->
|
||||
when List.get initialList high is
|
||||
Ok pivot ->
|
||||
when partitionHelp (low - 1) low initialList high pivot is
|
||||
Pair newI newList ->
|
||||
Pair (newI + 1) (swap (newI + 1) high newList)
|
||||
partition = \low, high, initial_list ->
|
||||
when List.get(initial_list, high) is
|
||||
Ok(pivot) ->
|
||||
when partition_help((low - 1), low, initial_list, high, pivot) is
|
||||
Pair(new_i, new_list) ->
|
||||
Pair((new_i + 1), swap((new_i + 1), high, new_list))
|
||||
|
||||
Err _ ->
|
||||
Pair (low - 1) initialList
|
||||
Err(_) ->
|
||||
Pair((low - 1), initial_list)
|
||||
|
||||
|
||||
partitionHelp : U64, U64, List (Num a), U64, (Num a) -> [Pair U64 (List (Num a))]
|
||||
partitionHelp = \i, j, list, high, pivot ->
|
||||
partition_help : U64, U64, List (Num a), U64, Num a -> [Pair U64 (List (Num a))]
|
||||
partition_help = \i, j, list, high, pivot ->
|
||||
if j < high then
|
||||
when List.get list j is
|
||||
Ok value ->
|
||||
when List.get(list, j) is
|
||||
Ok(value) ->
|
||||
if value <= pivot then
|
||||
partitionHelp (i + 1) (j + 1) (swap (i + 1) j list) high pivot
|
||||
partition_help((i + 1), (j + 1), swap((i + 1), j, list), high, pivot)
|
||||
else
|
||||
partitionHelp i (j + 1) list high pivot
|
||||
partition_help(i, (j + 1), list, high, pivot)
|
||||
|
||||
Err _ ->
|
||||
Pair i list
|
||||
Err(_) ->
|
||||
Pair(i, list)
|
||||
else
|
||||
Pair i list
|
||||
Pair(i, list)
|
||||
|
||||
|
||||
|
||||
quicksort = \originalList ->
|
||||
n = List.len originalList
|
||||
quicksortHelp originalList 0 (n - 1)
|
||||
quicksort = \original_list ->
|
||||
n = List.len(original_list)
|
||||
quicksort_help(original_list, 0, (n - 1))
|
||||
|
|
|
@ -1,8 +1,6 @@
|
|||
interface Records
|
||||
exposes [intVal]
|
||||
imports []
|
||||
module [int_val]
|
||||
|
||||
intVal =
|
||||
int_val =
|
||||
foo = \{ x } -> x
|
||||
|
||||
foo { x: 5 }
|
||||
foo({ x: 5 })
|
||||
|
|
|
@ -1,31 +1,29 @@
|
|||
interface Res
|
||||
exposes [Res, withDefault, map, andThen, ConsList]
|
||||
imports []
|
||||
module [Res, with_default, map, and_then, ConsList]
|
||||
|
||||
Res ok err : [Ok ok, Err err]
|
||||
|
||||
ConsList a : [Cons a (ConsList a), Nil]
|
||||
|
||||
listMap : ConsList a, (a -> b) -> ConsList b
|
||||
listMap = \list, f ->
|
||||
when list is
|
||||
Nil -> Nil
|
||||
Cons x xs -> Cons (f x) (listMap xs f)
|
||||
list_map : ConsList a, (a -> b) -> ConsList b
|
||||
list_map = \list, f ->
|
||||
when list is
|
||||
Nil -> Nil
|
||||
Cons(x, xs) -> Cons(f(x), list_map(xs, f))
|
||||
|
||||
map : Res a err, (a -> b) -> Res b err
|
||||
map = \result, transform ->
|
||||
when result is
|
||||
Ok ok -> Ok (transform ok)
|
||||
Err err -> Err err
|
||||
Ok(ok) -> Ok(transform(ok))
|
||||
Err(err) -> Err(err)
|
||||
|
||||
withDefault : Res a err, a -> a
|
||||
withDefault = \result, default ->
|
||||
with_default : Res a err, a -> a
|
||||
with_default = \result, default ->
|
||||
when result is
|
||||
Ok ok -> ok
|
||||
Err _ -> default
|
||||
Ok(ok) -> ok
|
||||
Err(_) -> default
|
||||
|
||||
andThen : Res a err, (a -> Res b err) -> Res b err
|
||||
andThen = \result, transform ->
|
||||
and_then : Res a err, (a -> Res b err) -> Res b err
|
||||
and_then = \result, transform ->
|
||||
when result is
|
||||
Ok ok -> transform ok
|
||||
Err err -> Err err
|
||||
Ok(ok) -> transform(ok)
|
||||
Err(err) -> Err(err)
|
||||
|
|
|
@ -1,22 +1,20 @@
|
|||
interface WithBuiltins
|
||||
exposes [floatTest, divisionFn, divisionTest, intTest, constantNum, fromDep2, divDep1ByDep2]
|
||||
imports []
|
||||
module [float_test, division_fn, division_test, int_test, constant_num, from_dep2, div_dep1_by_dep2]
|
||||
|
||||
import Dep1
|
||||
import Dep2 exposing [two]
|
||||
|
||||
floatTest = Num.maxF64
|
||||
float_test = Num.max_f64
|
||||
|
||||
divisionFn = Num.div
|
||||
division_fn = Num.div
|
||||
|
||||
x = 5.0
|
||||
|
||||
divisionTest = Num.maxF64 / x
|
||||
division_test = Num.max_f64 / x
|
||||
|
||||
intTest = Num.maxI64
|
||||
int_test = Num.max_i64
|
||||
|
||||
constantNum = 5
|
||||
constant_num = 5
|
||||
|
||||
fromDep2 = Dep2.two
|
||||
from_dep2 = Dep2.two
|
||||
|
||||
divDep1ByDep2 = Dep1.three / fromDep2
|
||||
div_dep1_by_dep2 = Dep1.three / from_dep2
|
||||
|
|
|
@ -1,111 +1,99 @@
|
|||
interface AStar
|
||||
exposes [initialModel, reconstructPath, updateCost, cheapestOpen, astar, findPath]
|
||||
imports []
|
||||
|
||||
module [initial_model, reconstruct_path, update_cost, cheapest_open, astar, find_path]
|
||||
|
||||
# a port of https://github.com/krisajenkins/elm-astar/blob/2.1.3/src/AStar/Generalised.elm
|
||||
|
||||
Model position :
|
||||
{ evaluated : Set position
|
||||
, openSet : Set position
|
||||
, costs : Dict.Dict position F64
|
||||
, cameFrom : Dict.Dict position position
|
||||
}
|
||||
Model position : {
|
||||
evaluated : Set position,
|
||||
open_set : Set position,
|
||||
costs : Dict.Dict position F64,
|
||||
came_from : Dict.Dict position position,
|
||||
}
|
||||
|
||||
initial_model : position -> Model position where position implements Hash & Eq
|
||||
initial_model = \start -> {
|
||||
evaluated: Set.empty({}),
|
||||
open_set: Set.single(start),
|
||||
costs: Dict.single(start, 0.0),
|
||||
came_from: Dict.empty({}),
|
||||
}
|
||||
|
||||
initialModel : position -> Model position where position implements Hash & Eq
|
||||
initialModel = \start ->
|
||||
{ evaluated : Set.empty {}
|
||||
, openSet : Set.single start
|
||||
, costs : Dict.single start 0.0
|
||||
, cameFrom : Dict.empty {}
|
||||
}
|
||||
cheapest_open : (position -> F64), Model position -> Result position [KeyNotFound] where position implements Hash & Eq
|
||||
cheapest_open = \cost_function, model ->
|
||||
|
||||
folder = \res_smallest_so_far, position ->
|
||||
when Dict.get(model.costs, position) is
|
||||
Err(e) ->
|
||||
Err(e)
|
||||
|
||||
cheapestOpen : (position -> F64), Model position -> Result position [KeyNotFound] where position implements Hash & Eq
|
||||
cheapestOpen = \costFunction, model ->
|
||||
Ok(cost) ->
|
||||
position_cost = cost_function(position)
|
||||
|
||||
folder = \resSmallestSoFar, position ->
|
||||
when Dict.get model.costs position is
|
||||
Err e ->
|
||||
Err e
|
||||
when res_smallest_so_far is
|
||||
Err(_) -> Ok({ position, cost: cost + position_cost })
|
||||
Ok(smallest_so_far) ->
|
||||
if position_cost + cost < smallest_so_far.cost then
|
||||
Ok({ position, cost: cost + position_cost })
|
||||
else
|
||||
Ok(smallest_so_far)
|
||||
|
||||
Ok cost ->
|
||||
positionCost = costFunction position
|
||||
Set.walk(model.open_set, Err(KeyNotFound), folder)
|
||||
|> Result.map(\x -> x.position)
|
||||
|
||||
when resSmallestSoFar is
|
||||
Err _ -> Ok { position, cost: cost + positionCost }
|
||||
Ok smallestSoFar ->
|
||||
if positionCost + cost < smallestSoFar.cost then
|
||||
Ok { position, cost: cost + positionCost }
|
||||
|
||||
else
|
||||
Ok smallestSoFar
|
||||
|
||||
Set.walk model.openSet (Err KeyNotFound) folder
|
||||
|> Result.map (\x -> x.position)
|
||||
|
||||
|
||||
|
||||
reconstructPath : Dict position position, position -> List position where position implements Hash & Eq
|
||||
reconstructPath = \cameFrom, goal ->
|
||||
when Dict.get cameFrom goal is
|
||||
Err KeyNotFound ->
|
||||
reconstruct_path : Dict position position, position -> List position where position implements Hash & Eq
|
||||
reconstruct_path = \came_from, goal ->
|
||||
when Dict.get(came_from, goal) is
|
||||
Err(KeyNotFound) ->
|
||||
[]
|
||||
|
||||
Ok next ->
|
||||
List.append (reconstructPath cameFrom next) goal
|
||||
Ok(next) ->
|
||||
List.append(reconstruct_path(came_from, next), goal)
|
||||
|
||||
updateCost : position, position, Model position -> Model position where position implements Hash & Eq
|
||||
updateCost = \current, neighbour, model ->
|
||||
newCameFrom = Dict.insert model.cameFrom neighbour current
|
||||
update_cost : position, position, Model position -> Model position where position implements Hash & Eq
|
||||
update_cost = \current, neighbour, model ->
|
||||
new_came_from = Dict.insert(model.came_from, neighbour, current)
|
||||
|
||||
newCosts = Dict.insert model.costs neighbour distanceTo
|
||||
new_costs = Dict.insert(model.costs, neighbour, distance_to)
|
||||
|
||||
distanceTo = reconstructPath newCameFrom neighbour
|
||||
|> List.len
|
||||
|> Num.toFrac
|
||||
distance_to =
|
||||
reconstruct_path(new_came_from, neighbour)
|
||||
|> List.len
|
||||
|> Num.to_frac
|
||||
|
||||
newModel = { model & costs : newCosts , cameFrom : newCameFrom }
|
||||
new_model = { model & costs: new_costs, came_from: new_came_from }
|
||||
|
||||
when Dict.get model.costs neighbour is
|
||||
Err KeyNotFound ->
|
||||
newModel
|
||||
|
||||
Ok previousDistance ->
|
||||
if distanceTo < previousDistance then
|
||||
newModel
|
||||
when Dict.get(model.costs, neighbour) is
|
||||
Err(KeyNotFound) ->
|
||||
new_model
|
||||
|
||||
Ok(previous_distance) ->
|
||||
if distance_to < previous_distance then
|
||||
new_model
|
||||
else
|
||||
model
|
||||
|
||||
|
||||
findPath : { costFunction: (position, position -> F64), moveFunction: (position -> Set position), start : position, end : position } -> Result (List position) [KeyNotFound] where position implements Hash & Eq
|
||||
findPath = \{ costFunction, moveFunction, start, end } ->
|
||||
astar costFunction moveFunction end (initialModel start)
|
||||
|
||||
find_path : { cost_function : position, position -> F64, move_function : position -> Set position, start : position, end : position } -> Result (List position) [KeyNotFound] where position implements Hash & Eq
|
||||
find_path = \{ cost_function, move_function, start, end } ->
|
||||
astar(cost_function, move_function, end, initial_model(start))
|
||||
|
||||
astar : (position, position -> F64), (position -> Set position), position, Model position -> [Err [KeyNotFound], Ok (List position)] where position implements Hash & Eq
|
||||
astar = \costFn, moveFn, goal, model ->
|
||||
when cheapestOpen (\position -> costFn goal position) model is
|
||||
Err _ ->
|
||||
Err KeyNotFound
|
||||
astar = \cost_fn, move_fn, goal, model ->
|
||||
when cheapest_open(\position -> cost_fn(goal, position), model) is
|
||||
Err(_) ->
|
||||
Err(KeyNotFound)
|
||||
|
||||
Ok current ->
|
||||
Ok(current) ->
|
||||
if current == goal then
|
||||
Ok (reconstructPath model.cameFrom goal)
|
||||
|
||||
Ok(reconstruct_path(model.came_from, goal))
|
||||
else
|
||||
model_popped = { model & open_set: Set.remove(model.open_set, current), evaluated: Set.insert(model.evaluated, current) }
|
||||
|
||||
modelPopped = { model & openSet : Set.remove model.openSet current, evaluated : Set.insert model.evaluated current }
|
||||
neighbours = move_fn(current)
|
||||
|
||||
neighbours = moveFn current
|
||||
new_neighbours = Set.difference(neighbours, model_popped.evaluated)
|
||||
|
||||
newNeighbours = Set.difference neighbours modelPopped.evaluated
|
||||
model_with_neighbours = { model_popped & open_set: Set.union(model_popped.open_set, new_neighbours) }
|
||||
|
||||
modelWithNeighbours = { modelPopped & openSet : Set.union modelPopped.openSet newNeighbours }
|
||||
model_with_costs = Set.walk(new_neighbours, model_with_neighbours, \md, nb -> update_cost(current, nb, md))
|
||||
|
||||
modelWithCosts = Set.walk newNeighbours modelWithNeighbours (\md, nb -> updateCost current nb md)
|
||||
|
||||
astar costFn moveFn goal modelWithCosts
|
||||
astar(cost_fn, move_fn, goal, model_with_costs)
|
||||
|
||||
|
|
|
@ -1,6 +1,4 @@
|
|||
interface Dep1
|
||||
exposes [three, str, Unit, Identity, one, two]
|
||||
imports []
|
||||
module [three, str, Unit, Identity, one, two]
|
||||
|
||||
import Dep3 exposing [foo]
|
||||
|
||||
|
|
|
@ -1,6 +1,4 @@
|
|||
interface Dep2
|
||||
exposes [one, two, blah]
|
||||
imports []
|
||||
module [one, two, blah]
|
||||
|
||||
import Dep3 exposing [foo, bar]
|
||||
|
||||
|
|
|
@ -1,6 +1,4 @@
|
|||
interface Dep3
|
||||
exposes [one, two, foo, bar]
|
||||
imports []
|
||||
module [one, two, foo, bar]
|
||||
|
||||
one = 1
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
interface ExposedUsedOutsideScope exposes [good, bad] imports []
|
||||
module [good, bad]
|
||||
|
||||
good =
|
||||
import Dep2 exposing [two]
|
||||
|
|
|
@ -1,6 +1,4 @@
|
|||
interface ImportAlias
|
||||
exposes [unit]
|
||||
imports []
|
||||
module [unit]
|
||||
|
||||
import Dep1
|
||||
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
interface ImportInsideDef exposes [dep1Str, dep2TwoDobuled] imports []
|
||||
module [dep1_str, dep2_two_dobuled]
|
||||
|
||||
dep1Str =
|
||||
dep1_str =
|
||||
import Dep1
|
||||
Dep1.str
|
||||
|
||||
dep2TwoDobuled =
|
||||
dep2_two_dobuled =
|
||||
2
|
||||
* (
|
||||
import Dep2 exposing [two]
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
interface ImportUsedOutsideScope exposes [good, bad] imports []
|
||||
module [good, bad]
|
||||
|
||||
good =
|
||||
import Dep2
|
||||
|
|
|
@ -1,6 +1,4 @@
|
|||
interface IngestedFile
|
||||
exposes [str, nested]
|
||||
imports []
|
||||
module [str, nested]
|
||||
|
||||
import "IngestedFile.roc" as foo : Str
|
||||
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
interface IngestedFileBytes
|
||||
exposes [str]
|
||||
imports []
|
||||
module [str]
|
||||
|
||||
import "IngestedFileBytes.roc" as foo : List U8
|
||||
|
||||
str = Str.fromUtf8 foo |> Result.withDefault ""
|
||||
str = Str.from_utf8(foo) |> Result.with_default("")
|
||||
|
|
|
@ -1,18 +1,16 @@
|
|||
interface ManualAttr
|
||||
exposes []
|
||||
imports []
|
||||
module []
|
||||
|
||||
# manually replicates the Attr wrapping that uniqueness inference uses, to try and find out why they are different
|
||||
# It is very important that there are no signatures here! elm uses an optimization that leads to less copying when
|
||||
# signatures are given.
|
||||
|
||||
map =
|
||||
unAttr = \Attr _ foobar -> foobar
|
||||
un_attr = \Attr(_, foobar) -> foobar
|
||||
|
||||
r = Attr unknown "bar"
|
||||
r = Attr(unknown, "bar")
|
||||
|
||||
s = Attr unknown2 { left : Attr Shared "foo" }
|
||||
s = Attr(unknown2, { left: Attr(Shared, "foo") })
|
||||
|
||||
when True is
|
||||
_ -> { y : r }
|
||||
_ -> { y : (unAttr s).left }
|
||||
_ -> { y: r }
|
||||
_ -> { y: (un_attr(s)).left }
|
||||
|
|
|
@ -1,6 +1,4 @@
|
|||
interface OneDep
|
||||
exposes [str]
|
||||
imports []
|
||||
module [str]
|
||||
|
||||
import Dep3 exposing [foo]
|
||||
|
||||
|
|
|
@ -1,6 +1,4 @@
|
|||
interface Primary
|
||||
exposes [blah2, blah3, str, alwaysThree, identity, z, w, succeed, withDefault, yay]
|
||||
imports []
|
||||
module [blah2, blah3, str, always_three, identity, z, w, succeed, with_default, yay]
|
||||
|
||||
import Dep1
|
||||
import Dep2
|
||||
|
@ -12,24 +10,24 @@ blah3 = bar
|
|||
|
||||
str = Dep1.str
|
||||
|
||||
alwaysThree = \_ -> Dep1.three
|
||||
always_three = \_ -> Dep1.three
|
||||
|
||||
identity = \a -> a
|
||||
|
||||
z = identity (alwaysThree {})
|
||||
z = identity(always_three({}))
|
||||
|
||||
w : Dep1.Identity {}
|
||||
w = Identity {}
|
||||
w = Identity({})
|
||||
|
||||
succeed : a -> Dep1.Identity a
|
||||
succeed = \x -> Identity x
|
||||
succeed = \x -> Identity(x)
|
||||
|
||||
withDefault = Res.withDefault
|
||||
with_default = Res.with_default
|
||||
|
||||
yay : Res.Res {} err
|
||||
yay =
|
||||
ok = Ok "foo"
|
||||
ok = Ok("foo")
|
||||
|
||||
f = \_ -> {}
|
||||
|
||||
Res.map ok f
|
||||
Res.map(ok, f)
|
||||
|
|
|
@ -1,51 +1,46 @@
|
|||
interface Quicksort
|
||||
exposes [swap, partition, quicksort]
|
||||
imports []
|
||||
module [swap, partition, quicksort]
|
||||
|
||||
quicksort : List (Num a), U64, U64 -> List (Num a)
|
||||
quicksort = \list, low, high ->
|
||||
when partition low high list is
|
||||
Pair partitionIndex partitioned ->
|
||||
when partition(low, high, list) is
|
||||
Pair(partition_index, partitioned) ->
|
||||
partitioned
|
||||
|> quicksort low (partitionIndex - 1)
|
||||
|> quicksort (partitionIndex + 1) high
|
||||
|
||||
|> quicksort(low, (partition_index - 1))
|
||||
|> quicksort((partition_index + 1), high)
|
||||
|
||||
swap : U64, U64, List a -> List a
|
||||
swap = \i, j, list ->
|
||||
when Pair (List.get list i) (List.get list j) is
|
||||
Pair (Ok atI) (Ok atJ) ->
|
||||
when Pair(List.get(list, i), List.get(list, j)) is
|
||||
Pair(Ok(at_i), Ok(at_j)) ->
|
||||
list
|
||||
|> List.set i atJ
|
||||
|> List.set j atI
|
||||
|> List.set(i, at_j)
|
||||
|> List.set(j, at_i)
|
||||
|
||||
_ ->
|
||||
[]
|
||||
|
||||
|
||||
partition : U64, U64, List (Num a) -> [Pair U64 (List (Num a))]
|
||||
partition = \low, high, initialList ->
|
||||
when List.get initialList high is
|
||||
Ok pivot ->
|
||||
when partitionHelp (low - 1) low initialList high pivot is
|
||||
Pair newI newList ->
|
||||
Pair (newI + 1) (swap (newI + 1) high newList)
|
||||
partition = \low, high, initial_list ->
|
||||
when List.get(initial_list, high) is
|
||||
Ok(pivot) ->
|
||||
when partition_help((low - 1), low, initial_list, high, pivot) is
|
||||
Pair(new_i, new_list) ->
|
||||
Pair((new_i + 1), swap((new_i + 1), high, new_list))
|
||||
|
||||
Err _ ->
|
||||
Pair (low - 1) initialList
|
||||
Err(_) ->
|
||||
Pair((low - 1), initial_list)
|
||||
|
||||
|
||||
partitionHelp : U64, U64, List (Num a), U64, (Num a) -> [Pair U64 (List (Num a))]
|
||||
partitionHelp = \i, j, list, high, pivot ->
|
||||
partition_help : U64, U64, List (Num a), U64, Num a -> [Pair U64 (List (Num a))]
|
||||
partition_help = \i, j, list, high, pivot ->
|
||||
if j < high then
|
||||
when List.get list j is
|
||||
Ok value ->
|
||||
when List.get(list, j) is
|
||||
Ok(value) ->
|
||||
if value <= pivot then
|
||||
partitionHelp (i + 1) (j + 1) (swap (i + 1) j list) high pivot
|
||||
partition_help((i + 1), (j + 1), swap((i + 1), j, list), high, pivot)
|
||||
else
|
||||
partitionHelp i (j + 1) list high pivot
|
||||
partition_help(i, (j + 1), list, high, pivot)
|
||||
|
||||
Err _ ->
|
||||
Pair i list
|
||||
Err(_) ->
|
||||
Pair(i, list)
|
||||
else
|
||||
Pair i list
|
||||
Pair(i, list)
|
||||
|
|
|
@ -1,8 +1,6 @@
|
|||
interface Records
|
||||
exposes [intVal]
|
||||
imports []
|
||||
module [int_val]
|
||||
|
||||
intVal =
|
||||
int_val =
|
||||
foo = \{ x } -> x
|
||||
|
||||
foo { x: 5 }
|
||||
foo({ x: 5 })
|
||||
|
|
|
@ -1,31 +1,29 @@
|
|||
interface Res
|
||||
exposes [Res, withDefault, map, listMap, andThen, ConsList]
|
||||
imports []
|
||||
module [Res, with_default, map, list_map, and_then, ConsList]
|
||||
|
||||
Res ok err : [Ok ok, Err err]
|
||||
|
||||
ConsList a : [Cons a (ConsList a), Nil]
|
||||
|
||||
listMap : ConsList a, (a -> b) -> ConsList b
|
||||
listMap = \list, f ->
|
||||
when list is
|
||||
Nil -> Nil
|
||||
Cons x xs -> Cons (f x) (listMap xs f)
|
||||
list_map : ConsList a, (a -> b) -> ConsList b
|
||||
list_map = \list, f ->
|
||||
when list is
|
||||
Nil -> Nil
|
||||
Cons(x, xs) -> Cons(f(x), list_map(xs, f))
|
||||
|
||||
map : Res a err, (a -> b) -> Res b err
|
||||
map = \result, transform ->
|
||||
when result is
|
||||
Ok ok -> Ok (transform ok)
|
||||
Err err -> Err err
|
||||
Ok(ok) -> Ok(transform(ok))
|
||||
Err(err) -> Err(err)
|
||||
|
||||
withDefault : Res a err, a -> a
|
||||
withDefault = \result, default ->
|
||||
with_default : Res a err, a -> a
|
||||
with_default = \result, default ->
|
||||
when result is
|
||||
Ok ok -> ok
|
||||
Err _ -> default
|
||||
Ok(ok) -> ok
|
||||
Err(_) -> default
|
||||
|
||||
andThen : Res a err, (a -> Res b err) -> Res b err
|
||||
andThen = \result, transform ->
|
||||
and_then : Res a err, (a -> Res b err) -> Res b err
|
||||
and_then = \result, transform ->
|
||||
when result is
|
||||
Ok ok -> transform ok
|
||||
Err err -> Err err
|
||||
Ok(ok) -> transform(ok)
|
||||
Err(err) -> Err(err)
|
||||
|
|
|
@ -1,22 +1,20 @@
|
|||
interface WithBuiltins
|
||||
exposes [floatTest, divisionFn, divisionTest, intTest, constantNum, fromDep2, divDep1ByDep2]
|
||||
imports []
|
||||
module [float_test, division_fn, division_test, int_test, constant_num, from_dep2, div_dep1_by_dep2]
|
||||
|
||||
import Dep1
|
||||
import Dep2
|
||||
|
||||
floatTest = Num.maxF64
|
||||
float_test = Num.max_f64
|
||||
|
||||
divisionFn = Num.div
|
||||
division_fn = Num.div
|
||||
|
||||
x = 5.0
|
||||
|
||||
divisionTest = Num.maxF64 / x
|
||||
division_test = Num.max_f64 / x
|
||||
|
||||
intTest = Num.maxI64
|
||||
int_test = Num.max_i64
|
||||
|
||||
constantNum = 5
|
||||
constant_num = 5
|
||||
|
||||
fromDep2 = Dep2.two
|
||||
from_dep2 = Dep2.two
|
||||
|
||||
divDep1ByDep2 = Dep1.three / fromDep2
|
||||
div_dep1_by_dep2 = Dep1.three / from_dep2
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
## An interface for docs tests
|
||||
interface Docs
|
||||
exposes [makeUser, getNameExposed]
|
||||
imports []
|
||||
module [make_user, get_name_exposed]
|
||||
|
||||
## This is a user
|
||||
User : { name : Str }
|
||||
|
@ -9,12 +7,12 @@ User : { name : Str }
|
|||
## Makes a user
|
||||
##
|
||||
## Takes a name Str.
|
||||
makeUser : Str -> User
|
||||
makeUser = \name ->
|
||||
make_user : Str -> User
|
||||
make_user = \name ->
|
||||
{ name }
|
||||
|
||||
## Gets the user's name
|
||||
getName = \a -> a.name
|
||||
get_name = \a -> a.name
|
||||
|
||||
getNameExposed = getName
|
||||
get_name_exposed = get_name
|
||||
|
||||
|
|
|
@ -1,6 +1,4 @@
|
|||
interface MissingDep
|
||||
exposes [unit]
|
||||
imports []
|
||||
module [unit]
|
||||
|
||||
import ThisFileIsMissing
|
||||
|
||||
|
|
|
@ -1,6 +1,4 @@
|
|||
interface MissingIngestedFile
|
||||
exposes [unit]
|
||||
imports []
|
||||
module [unit]
|
||||
|
||||
import "ThisFileIsMissing" as data : List U8
|
||||
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
interface Principal
|
||||
exposes [identity, intVal]
|
||||
imports []
|
||||
module [identity, int_val]
|
||||
|
||||
identity = \a -> a
|
||||
|
||||
intVal = identity "hi"
|
||||
int_val = identity("hi")
|
||||
|
|
|
@ -1,6 +1,4 @@
|
|||
interface Unit
|
||||
exposes [unit]
|
||||
imports []
|
||||
module [unit]
|
||||
|
||||
Unit : [Unit]
|
||||
|
||||
|
|
|
@ -512,11 +512,11 @@ fn load_docs() {
|
|||
(None, Some("An interface for docs tests\n")),
|
||||
(Some("User"), Some("This is a user\n")),
|
||||
(
|
||||
Some("makeUser"),
|
||||
Some("make_user"),
|
||||
Some("Makes a user\n\nTakes a name Str.\n"),
|
||||
),
|
||||
(Some("getName"), Some("Gets the user's name\n")),
|
||||
(Some("getNameExposed"), None),
|
||||
(Some("get_name"), Some("Gets the user's name\n")),
|
||||
(Some("get_name_exposed"), None),
|
||||
]
|
||||
.into_iter()
|
||||
.map(|(ident_str_opt, doc_str_opt)| {
|
||||
|
@ -553,8 +553,8 @@ fn import_inside_def() {
|
|||
expect_types(
|
||||
loaded_module,
|
||||
hashmap! {
|
||||
"dep1Str" => "Str",
|
||||
"dep2TwoDobuled" => "Frac *",
|
||||
"dep1_str" => "Str",
|
||||
"dep2_two_dobuled" => "Frac *",
|
||||
},
|
||||
);
|
||||
}
|
||||
|
@ -585,15 +585,15 @@ fn test_load_and_typecheck() {
|
|||
expect_types(
|
||||
loaded_module,
|
||||
hashmap! {
|
||||
"floatTest" => "F64",
|
||||
"divisionFn" => "Frac a, Frac a -> Frac a",
|
||||
"float_test" => "F64",
|
||||
"division_fn" => "Frac a, Frac a -> Frac a",
|
||||
"x" => "Frac *",
|
||||
"divisionTest" => "F64",
|
||||
"intTest" => "I64",
|
||||
"constantNum" => "Num *",
|
||||
"divisionTest" => "F64",
|
||||
"divDep1ByDep2" => "Frac a",
|
||||
"fromDep2" => "Frac a",
|
||||
"division_test" => "F64",
|
||||
"int_test" => "I64",
|
||||
"constant_num" => "Num *",
|
||||
"division_test" => "F64",
|
||||
"div_dep1_by_dep2" => "Frac a",
|
||||
"from_dep2" => "Frac a",
|
||||
},
|
||||
);
|
||||
}
|
||||
|
@ -608,7 +608,7 @@ fn iface_quicksort() {
|
|||
hashmap! {
|
||||
"swap" => "U64, U64, List a -> List a",
|
||||
"partition" => "U64, U64, List (Num a) -> [Pair U64 (List (Num a))]",
|
||||
"partitionHelp" => "U64, U64, List (Num a), U64, Num a -> [Pair U64 (List (Num a))]",
|
||||
"partition_help" => "U64, U64, List (Num a), U64, Num a -> [Pair U64 (List (Num a))]",
|
||||
"quicksort" => "List (Num a), U64, U64 -> List (Num a)",
|
||||
},
|
||||
);
|
||||
|
@ -622,11 +622,11 @@ fn load_astar() {
|
|||
expect_types(
|
||||
loaded_module,
|
||||
hashmap! {
|
||||
"findPath" => "{ costFunction : position, position -> F64, end : position, moveFunction : position -> Set position, start : position } -> Result (List position) [KeyNotFound] where position implements Hash & Eq",
|
||||
"initialModel" => "position -> Model position where position implements Hash & Eq",
|
||||
"reconstructPath" => "Dict position position, position -> List position where position implements Hash & Eq",
|
||||
"updateCost" => "position, position, Model position -> Model position where position implements Hash & Eq",
|
||||
"cheapestOpen" => "(position -> F64), Model position -> Result position [KeyNotFound] where position implements Hash & Eq",
|
||||
"find_path" => "{ cost_function : position, position -> F64, end : position, move_function : position -> Set position, start : position } -> Result (List position) [KeyNotFound] where position implements Hash & Eq",
|
||||
"initial_model" => "position -> Model position where position implements Hash & Eq",
|
||||
"reconstruct_path" => "Dict position position, position -> List position where position implements Hash & Eq",
|
||||
"update_cost" => "position, position, Model position -> Model position where position implements Hash & Eq",
|
||||
"cheapest_open" => "(position -> F64), Model position -> Result position [KeyNotFound] where position implements Hash & Eq",
|
||||
"astar" => "(position, position -> F64), (position -> Set position), position, Model position -> [Err [KeyNotFound], Ok (List position)] where position implements Hash & Eq",
|
||||
},
|
||||
);
|
||||
|
@ -640,7 +640,7 @@ fn load_principal_types() {
|
|||
expect_types(
|
||||
loaded_module,
|
||||
hashmap! {
|
||||
"intVal" => "Str",
|
||||
"int_val" => "Str",
|
||||
"identity" => "a -> a",
|
||||
},
|
||||
);
|
||||
|
@ -657,13 +657,13 @@ fn iface_dep_types() {
|
|||
"blah2" => "Frac *",
|
||||
"blah3" => "Str",
|
||||
"str" => "Str",
|
||||
"alwaysThree" => "* -> Frac *",
|
||||
"always_three" => "* -> Frac *",
|
||||
"identity" => "a -> a",
|
||||
"z" => "Frac *",
|
||||
"w" => "Dep1.Identity {}",
|
||||
"succeed" => "a -> Dep1.Identity a",
|
||||
"yay" => "Res.Res {} err",
|
||||
"withDefault" => "Res.Res a err, a -> a",
|
||||
"with_default" => "Res.Res a err, a -> a",
|
||||
},
|
||||
);
|
||||
}
|
||||
|
@ -679,13 +679,13 @@ fn app_dep_types() {
|
|||
"blah2" => "Frac *",
|
||||
"blah3" => "Str",
|
||||
"str" => "Str",
|
||||
"alwaysThree" => "* -> Frac *",
|
||||
"always_three" => "* -> Frac *",
|
||||
"identity" => "a -> a",
|
||||
"z" => "Frac *",
|
||||
"w" => "Dep1.Identity {}",
|
||||
"succeed" => "a -> Dep1.Identity a",
|
||||
"yay" => "Res.Res {} err",
|
||||
"withDefault" => "Res.Res a err, a -> a",
|
||||
"with_default" => "Res.Res a err, a -> a",
|
||||
},
|
||||
);
|
||||
}
|
||||
|
@ -897,13 +897,13 @@ fn opaque_wrapped_unwrapped_outside_defining_module() {
|
|||
"Main.roc",
|
||||
indoc!(
|
||||
r"
|
||||
module [twenty, readAge]
|
||||
module [twenty, read_age]
|
||||
|
||||
import Age exposing [Age]
|
||||
|
||||
twenty = @Age 20
|
||||
|
||||
readAge = \@Age n -> n
|
||||
read_age = \@Age n -> n
|
||||
"
|
||||
),
|
||||
),
|
||||
|
@ -933,8 +933,8 @@ fn opaque_wrapped_unwrapped_outside_defining_module() {
|
|||
|
||||
The unwrapped opaque type Age referenced here:
|
||||
|
||||
7│ readAge = \@Age n -> n
|
||||
^^^^
|
||||
7│ read_age = \@Age n -> n
|
||||
^^^^
|
||||
|
||||
is imported from another module:
|
||||
|
||||
|
@ -997,27 +997,27 @@ fn unused_imports() {
|
|||
"Main.roc",
|
||||
indoc!(
|
||||
r#"
|
||||
module [usedModule, unusedModule, unusedExposed, usingThreeValue, unusedWithAlias]
|
||||
module [used_module, unused_module, unused_exposed, using_three_value, unused_with_alias]
|
||||
|
||||
import Dep1
|
||||
import Dep3 exposing [Three]
|
||||
|
||||
usedModule =
|
||||
used_module =
|
||||
import Dep2
|
||||
Dep2.two
|
||||
|
||||
unusedModule =
|
||||
unused_module =
|
||||
import Dep2
|
||||
2
|
||||
|
||||
unusedExposed =
|
||||
unused_exposed =
|
||||
import Dep2 exposing [two]
|
||||
2
|
||||
|
||||
usingThreeValue =
|
||||
using_three_value =
|
||||
Dep3.three
|
||||
|
||||
unusedWithAlias =
|
||||
unused_with_alias =
|
||||
import Dep2 as D2
|
||||
2
|
||||
"#
|
||||
|
@ -1191,13 +1191,13 @@ fn explicit_builtin_type_import() {
|
|||
r#"
|
||||
interface Main exposes [main] imports []
|
||||
|
||||
import Dict exposing [Dict, isEmpty]
|
||||
import Dict exposing [Dict, is_empty]
|
||||
|
||||
myDict : Dict * *
|
||||
myDict =
|
||||
my_dict : Dict * *
|
||||
my_dict =
|
||||
Dict.empty {}
|
||||
|
||||
main = isEmpty myDict
|
||||
main = is_empty my_dict
|
||||
"#
|
||||
),
|
||||
)];
|
||||
|
@ -1210,7 +1210,7 @@ fn explicit_builtin_type_import() {
|
|||
|
||||
`Dict.Dict` was imported here:
|
||||
|
||||
3│ import Dict exposing [Dict, isEmpty]
|
||||
3│ import Dict exposing [Dict, is_empty]
|
||||
^^^^
|
||||
|
||||
All types from builtins are automatically exposed, so you can remove
|
||||
|
@ -1490,9 +1490,9 @@ fn alias_using_builtin_name() {
|
|||
"BoolExtra.roc",
|
||||
indoc!(
|
||||
r"
|
||||
interface BoolExtra exposes [toNum] imports []
|
||||
interface BoolExtra exposes [to_num] imports []
|
||||
|
||||
toNum = \value ->
|
||||
to_num = \value ->
|
||||
if value then 1 else 0
|
||||
"
|
||||
),
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -1,9 +1,9 @@
|
|||
app "test" provides [isEqQ] to "./platform"
|
||||
app "test" provides [is_eq_q] to "./platform"
|
||||
|
||||
Q := [ F (Str -> Str), G ] implements [Eq { isEq: isEqQ }]
|
||||
Q := [ F (Str -> Str), G ] implements [Eq { is_eq: is_eq_q }]
|
||||
|
||||
isEqQ = \@Q q1, @Q q2 -> when T q1 q2 is
|
||||
#^^^^^{-1} Q, Q -[[isEqQ(0)]]-> Bool
|
||||
is_eq_q = \@Q q1, @Q q2 -> when T q1 q2 is
|
||||
#^^^^^^^{-1} Q, Q -[[is_eq_q(0)]]-> Bool
|
||||
T (F _) (F _) -> Bool.true
|
||||
T G G -> Bool.true
|
||||
_ -> Bool.false
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
# +opt infer:print_only_under_alias
|
||||
app "test" provides [main] to "./platform"
|
||||
|
||||
Q := ({} -> Str) implements [Eq {isEq: isEqQ}]
|
||||
Q := ({} -> Str) implements [Eq {is_eq: is_eq_q}]
|
||||
|
||||
isEqQ = \@Q f1, @Q f2 -> (f1 {} == f2 {})
|
||||
#^^^^^{-1} ({} -[[]]-> Str), ({} -[[]]-> Str) -[[isEqQ(2)]]-> [False, True]
|
||||
is_eq_q = \@Q f1, @Q f2 -> (f1 {} == f2 {})
|
||||
#^^^^^^^{-1} ({} -[[]]-> Str), ({} -[[]]-> Str) -[[is_eq_q(2)]]-> [False, True]
|
||||
|
||||
main = isEqQ (@Q \{} -> "a") (@Q \{} -> "a")
|
||||
# ^^^^^ ({} -[[6, 7]]-> Str), ({} -[[6, 7]]-> Str) -[[isEqQ(2)]]-> [False, True]
|
||||
main = is_eq_q (@Q \{} -> "a") (@Q \{} -> "a")
|
||||
# ^^^^^^^ ({} -[[6, 7]]-> Str), ({} -[[6, 7]]-> Str) -[[is_eq_q(2)]]-> [False, True]
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
app "test" provides [myU8] to "./platform"
|
||||
app "test" provides [my_u8] to "./platform"
|
||||
|
||||
MDecodeError : [TooShort, Leftover (List U8)]
|
||||
|
||||
|
@ -10,16 +10,16 @@ MDecoding implements
|
|||
MDecoderFormatting implements
|
||||
u8 : MDecoder U8 fmt where fmt implements MDecoderFormatting
|
||||
|
||||
decodeWith : List U8, MDecoder val fmt, fmt -> { result: Result val MDecodeError, rest: List U8 } where fmt implements MDecoderFormatting
|
||||
decodeWith = \lst, (@MDecoder doDecode), fmt -> doDecode lst fmt
|
||||
decode_with : List U8, MDecoder val fmt, fmt -> { result: Result val MDecodeError, rest: List U8 } where fmt implements MDecoderFormatting
|
||||
decode_with = \lst, (@MDecoder doDecode), fmt -> doDecode lst fmt
|
||||
|
||||
fromBytes : List U8, fmt -> Result val MDecodeError
|
||||
from_bytes : List U8, fmt -> Result val MDecodeError
|
||||
where fmt implements MDecoderFormatting, val implements MDecoding
|
||||
fromBytes = \lst, fmt ->
|
||||
when decodeWith lst decoder fmt is
|
||||
from_bytes = \lst, fmt ->
|
||||
when decode_with lst decoder fmt is
|
||||
{ result, rest } ->
|
||||
when result is
|
||||
Ok val -> if List.isEmpty rest then Ok val else Err (Leftover rest)
|
||||
Ok val -> if List.is_empty rest then Ok val else Err (Leftover rest)
|
||||
Err e -> Err e
|
||||
|
||||
|
||||
|
@ -28,17 +28,17 @@ Linear := {} implements [MDecoderFormatting {u8}]
|
|||
u8 = @MDecoder \lst, @Linear {} ->
|
||||
#^^{-1} Linear#u8(11): MDecoder U8 Linear
|
||||
when List.first lst is
|
||||
Ok n -> { result: Ok n, rest: List.dropFirst lst 1 }
|
||||
Ok n -> { result: Ok n, rest: List.drop_first lst 1 }
|
||||
Err _ -> { result: Err TooShort, rest: [] }
|
||||
|
||||
MyU8 := U8 implements [MDecoding {decoder}]
|
||||
|
||||
decoder = @MDecoder \lst, fmt ->
|
||||
#^^^^^^^{-1} MyU8#decoder(12): MDecoder MyU8 fmt where fmt implements MDecoderFormatting
|
||||
when decodeWith lst u8 fmt is
|
||||
when decode_with lst u8 fmt is
|
||||
{ result, rest } ->
|
||||
{ result: Result.map result (\n -> @MyU8 n), rest }
|
||||
|
||||
myU8 : Result MyU8 _
|
||||
myU8 = fromBytes [15] (@Linear {})
|
||||
#^^^^{-1} Result MyU8 MDecodeError
|
||||
my_u8 : Result MyU8 _
|
||||
my_u8 = from_bytes [15] (@Linear {})
|
||||
#^^^^^{-1} Result MyU8 MDecodeError
|
||||
|
|
|
@ -1,18 +1,18 @@
|
|||
app "test" provides [myU8Bytes] to "./platform"
|
||||
app "test" provides [my_u8_bytes] to "./platform"
|
||||
|
||||
MEncoder fmt := List U8, fmt -> List U8 where fmt implements Format
|
||||
|
||||
MEncoding implements
|
||||
toEncoder : val -> MEncoder fmt where val implements MEncoding, fmt implements Format
|
||||
to_encoder : val -> MEncoder fmt where val implements MEncoding, fmt implements Format
|
||||
|
||||
Format implements
|
||||
u8 : U8 -> MEncoder fmt where fmt implements Format
|
||||
|
||||
appendWith : List U8, MEncoder fmt, fmt -> List U8 where fmt implements Format
|
||||
appendWith = \lst, (@MEncoder doFormat), fmt -> doFormat lst fmt
|
||||
append_with : List U8, MEncoder fmt, fmt -> List U8 where fmt implements Format
|
||||
append_with = \lst, (@MEncoder doFormat), fmt -> doFormat lst fmt
|
||||
|
||||
toBytes : val, fmt -> List U8 where val implements MEncoding, fmt implements Format
|
||||
toBytes = \val, fmt -> appendWith [] (toEncoder val) fmt
|
||||
to_bytes : val, fmt -> List U8 where val implements MEncoding, fmt implements Format
|
||||
to_bytes = \val, fmt -> append_with [] (to_encoder val) fmt
|
||||
|
||||
|
||||
Linear := {} implements [Format {u8}]
|
||||
|
@ -20,10 +20,10 @@ Linear := {} implements [Format {u8}]
|
|||
u8 = \n -> @MEncoder (\lst, @Linear {} -> List.append lst n)
|
||||
#^^{-1} Linear#u8(10): U8 -[[u8(10)]]-> MEncoder Linear
|
||||
|
||||
MyU8 := U8 implements [MEncoding {toEncoder}]
|
||||
MyU8 := U8 implements [MEncoding {to_encoder}]
|
||||
|
||||
toEncoder = \@MyU8 n -> u8 n
|
||||
#^^^^^^^^^{-1} MyU8#toEncoder(11): MyU8 -[[toEncoder(11)]]-> MEncoder fmt where fmt implements Format
|
||||
to_encoder = \@MyU8 n -> u8 n
|
||||
#^^^^^^^^^^{-1} MyU8#to_encoder(11): MyU8 -[[to_encoder(11)]]-> MEncoder fmt where fmt implements Format
|
||||
|
||||
myU8Bytes = toBytes (@MyU8 15) (@Linear {})
|
||||
#^^^^^^^^^{-1} List U8
|
||||
my_u8_bytes = to_bytes (@MyU8 15) (@Linear {})
|
||||
#^^^^^^^^^^^{-1} List U8
|
||||
|
|
|
@ -2,5 +2,5 @@ app "test" provides [main] to "./platform"
|
|||
|
||||
main : Decoder Bool _
|
||||
main = Decode.custom \bytes, fmt ->
|
||||
Decode.decodeWith bytes Decode.decoder fmt
|
||||
# ^^^^^^^^^^^^^^ Decoding#Decode.decoder(4): Decoder Bool fmt where fmt implements DecoderFormatting
|
||||
Decode.decode_with bytes Decode.decoder fmt
|
||||
# ^^^^^^^^^^^^^^ Decoding#Decode.decoder(4): Decoder Bool fmt where fmt implements DecoderFormatting
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
app "test" provides [main] to "./platform"
|
||||
|
||||
main = Bool.isEq Bool.true Bool.false
|
||||
# ^^^^^^^^^ Eq#Bool.isEq(9): Bool, Bool -[[Bool.structuralEq(11)]]-> Bool
|
||||
main = Bool.is_eq Bool.true Bool.false
|
||||
# ^^^^^^^^^^ Eq#Bool.is_eq(9): Bool, Bool -[[Bool.structural_eq(11)]]-> Bool
|
||||
|
|
|
@ -2,4 +2,4 @@ app "test" provides [main] to "./platform"
|
|||
|
||||
main =
|
||||
\h -> Hash.hash h Bool.true
|
||||
# ^^^^^^^^^ Hash#Hash.hash(1): a, Bool -[[Hash.hashBool(9)]]-> a where a implements Hasher
|
||||
# ^^^^^^^^^ Hash#Hash.hash(1): a, Bool -[[Hash.hash_bool(9)]]-> a where a implements Hasher
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
app "test" provides [main] to "./platform"
|
||||
|
||||
main = Encode.toEncoder Bool.true
|
||||
# ^^^^^^^^^^^^^^^^ Encoding#Encode.toEncoder(2): Bool -[[] + fmt:Encode.bool(17):1]-> Encoder fmt where fmt implements EncoderFormatting
|
||||
main = Encode.to_encoder Bool.true
|
||||
# ^^^^^^^^^^^^^^^^^ Encoding#Encode.to_encoder(2): Bool -[[] + fmt:Encode.bool(17):1]-> Encoder fmt where fmt implements EncoderFormatting
|
||||
|
|
|
@ -2,4 +2,4 @@ app "test" provides [main] to "./platform"
|
|||
|
||||
main =
|
||||
\h -> Hash.hash h 1.1dec
|
||||
# ^^^^^^^^^ Hash#Hash.hash(1): a, Dec -[[Hash.hashDec(17)]]-> a where a implements Hasher
|
||||
# ^^^^^^^^^ Hash#Hash.hash(1): a, Dec -[[Hash.hash_dec(17)]]-> a where a implements Hasher
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
app "test" provides [main] to "./platform"
|
||||
|
||||
main = Inspect.toInspector Bool.true |> Inspect.apply (Inspect.init {})
|
||||
# ^^^^^^^^^^^^^^^^^^^ Inspect#Inspect.toInspector(32): Bool -[[] + f:Inspect.bool(13):1]-> Inspector f where f implements InspectFormatter
|
||||
main = Inspect.to_inspector Bool.true |> Inspect.apply (Inspect.init {})
|
||||
# ^^^^^^^^^^^^^^^^^^^^ Inspect#Inspect.to_inspector(32): Bool -[[] + f:Inspect.bool(13):1]-> Inspector f where f implements InspectFormatter
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
app "test" provides [main] to "./platform"
|
||||
|
||||
main = Inspect.toInspector 7dec |> Inspect.apply (Inspect.init {})
|
||||
# ^^^^^^^^^^^^^^^^^^^ Inspect#Inspect.toInspector(32): Dec -[[] + f:Inspect.dec(29):1]-> Inspector f where f implements InspectFormatter
|
||||
main = Inspect.to_inspector 7dec |> Inspect.apply (Inspect.init {})
|
||||
# ^^^^^^^^^^^^^^^^^^^^ Inspect#Inspect.to_inspector(32): Dec -[[] + f:Inspect.dec(29):1]-> Inspector f where f implements InspectFormatter
|
||||
|
|
|
@ -2,5 +2,5 @@ app "test" provides [main] to "./platform"
|
|||
|
||||
Op := {}
|
||||
|
||||
main = Inspect.toInspector (@Op {}) |> Inspect.apply (Inspect.init {})
|
||||
# ^^^^^^^^^^^^^^^^^^^ Inspect#Inspect.toInspector(32): Op -[[] + f:Inspect.opaque(15):1]-> Inspector f where f implements InspectFormatter
|
||||
main = Inspect.to_inspector (@Op {}) |> Inspect.apply (Inspect.init {})
|
||||
# ^^^^^^^^^^^^^^^^^^^^ Inspect#Inspect.to_inspector(32): Op -[[] + f:Inspect.opaque(15):1]-> Inspector f where f implements InspectFormatter
|
||||
|
|
|
@ -8,42 +8,42 @@ main =
|
|||
1
|
||||
|
||||
# -emit:mono
|
||||
procedure Inspect.252 (Inspect.253):
|
||||
let Inspect.317 : Str = "<opaque>";
|
||||
let Inspect.316 : Str = CallByName Inspect.63 Inspect.253 Inspect.317;
|
||||
dec Inspect.317;
|
||||
ret Inspect.316;
|
||||
procedure Inspect.251 (Inspect.252):
|
||||
let Inspect.316 : Str = "<opaque>";
|
||||
let Inspect.315 : Str = CallByName Inspect.63 Inspect.252 Inspect.316;
|
||||
dec Inspect.316;
|
||||
ret Inspect.315;
|
||||
|
||||
procedure Inspect.30 (Inspect.147):
|
||||
ret Inspect.147;
|
||||
|
||||
procedure Inspect.33 (Inspect.152):
|
||||
let Inspect.305 : Str = CallByName Inspect.5 Inspect.152;
|
||||
let Inspect.304 : Str = CallByName Inspect.64 Inspect.305;
|
||||
ret Inspect.304;
|
||||
let Inspect.304 : Str = CallByName Inspect.5 Inspect.152;
|
||||
let Inspect.303 : Str = CallByName Inspect.64 Inspect.304;
|
||||
ret Inspect.303;
|
||||
|
||||
procedure Inspect.39 (Inspect.301):
|
||||
let Inspect.311 : Str = "";
|
||||
ret Inspect.311;
|
||||
procedure Inspect.39 (Inspect.300):
|
||||
let Inspect.310 : Str = "";
|
||||
ret Inspect.310;
|
||||
|
||||
procedure Inspect.48 (Inspect.299):
|
||||
let Inspect.314 : {} = Struct {};
|
||||
let Inspect.313 : {} = CallByName Inspect.30 Inspect.314;
|
||||
ret Inspect.313;
|
||||
procedure Inspect.48 (Inspect.298):
|
||||
let Inspect.313 : {} = Struct {};
|
||||
let Inspect.312 : {} = CallByName Inspect.30 Inspect.313;
|
||||
ret Inspect.312;
|
||||
|
||||
procedure Inspect.5 (Inspect.150):
|
||||
let Inspect.312 : {} = CallByName Inspect.48 Inspect.150;
|
||||
let Inspect.309 : {} = Struct {};
|
||||
let Inspect.308 : Str = CallByName Inspect.39 Inspect.309;
|
||||
let Inspect.307 : Str = CallByName Inspect.252 Inspect.308;
|
||||
ret Inspect.307;
|
||||
let Inspect.311 : {} = CallByName Inspect.48 Inspect.150;
|
||||
let Inspect.308 : {} = Struct {};
|
||||
let Inspect.307 : Str = CallByName Inspect.39 Inspect.308;
|
||||
let Inspect.306 : Str = CallByName Inspect.251 Inspect.307;
|
||||
ret Inspect.306;
|
||||
|
||||
procedure Inspect.63 (Inspect.300, Inspect.296):
|
||||
let Inspect.319 : Str = CallByName Str.3 Inspect.300 Inspect.296;
|
||||
ret Inspect.319;
|
||||
procedure Inspect.63 (Inspect.299, Inspect.295):
|
||||
let Inspect.318 : Str = CallByName Str.3 Inspect.299 Inspect.295;
|
||||
ret Inspect.318;
|
||||
|
||||
procedure Inspect.64 (Inspect.302):
|
||||
ret Inspect.302;
|
||||
procedure Inspect.64 (Inspect.301):
|
||||
ret Inspect.301;
|
||||
|
||||
procedure Str.3 (#Attr.2, #Attr.3):
|
||||
let Str.246 : Str = lowlevel StrConcat #Attr.2 #Attr.3;
|
||||
|
|
|
@ -11,42 +11,42 @@ main =
|
|||
late (@Op {})
|
||||
|
||||
# -emit:mono
|
||||
procedure Inspect.252 (Inspect.253):
|
||||
let Inspect.317 : Str = "<opaque>";
|
||||
let Inspect.316 : Str = CallByName Inspect.63 Inspect.253 Inspect.317;
|
||||
dec Inspect.317;
|
||||
ret Inspect.316;
|
||||
procedure Inspect.251 (Inspect.252):
|
||||
let Inspect.316 : Str = "<opaque>";
|
||||
let Inspect.315 : Str = CallByName Inspect.63 Inspect.252 Inspect.316;
|
||||
dec Inspect.316;
|
||||
ret Inspect.315;
|
||||
|
||||
procedure Inspect.30 (Inspect.147):
|
||||
ret Inspect.147;
|
||||
|
||||
procedure Inspect.33 (Inspect.152):
|
||||
let Inspect.305 : Str = CallByName Inspect.5 Inspect.152;
|
||||
let Inspect.304 : Str = CallByName Inspect.64 Inspect.305;
|
||||
ret Inspect.304;
|
||||
let Inspect.304 : Str = CallByName Inspect.5 Inspect.152;
|
||||
let Inspect.303 : Str = CallByName Inspect.64 Inspect.304;
|
||||
ret Inspect.303;
|
||||
|
||||
procedure Inspect.39 (Inspect.301):
|
||||
let Inspect.311 : Str = "";
|
||||
ret Inspect.311;
|
||||
procedure Inspect.39 (Inspect.300):
|
||||
let Inspect.310 : Str = "";
|
||||
ret Inspect.310;
|
||||
|
||||
procedure Inspect.48 (Inspect.299):
|
||||
let Inspect.314 : {} = Struct {};
|
||||
let Inspect.313 : {} = CallByName Inspect.30 Inspect.314;
|
||||
ret Inspect.313;
|
||||
procedure Inspect.48 (Inspect.298):
|
||||
let Inspect.313 : {} = Struct {};
|
||||
let Inspect.312 : {} = CallByName Inspect.30 Inspect.313;
|
||||
ret Inspect.312;
|
||||
|
||||
procedure Inspect.5 (Inspect.150):
|
||||
let Inspect.312 : {} = CallByName Inspect.48 Inspect.150;
|
||||
let Inspect.309 : {} = Struct {};
|
||||
let Inspect.308 : Str = CallByName Inspect.39 Inspect.309;
|
||||
let Inspect.307 : Str = CallByName Inspect.252 Inspect.308;
|
||||
ret Inspect.307;
|
||||
let Inspect.311 : {} = CallByName Inspect.48 Inspect.150;
|
||||
let Inspect.308 : {} = Struct {};
|
||||
let Inspect.307 : Str = CallByName Inspect.39 Inspect.308;
|
||||
let Inspect.306 : Str = CallByName Inspect.251 Inspect.307;
|
||||
ret Inspect.306;
|
||||
|
||||
procedure Inspect.63 (Inspect.300, Inspect.296):
|
||||
let Inspect.319 : Str = CallByName Str.3 Inspect.300 Inspect.296;
|
||||
ret Inspect.319;
|
||||
procedure Inspect.63 (Inspect.299, Inspect.295):
|
||||
let Inspect.318 : Str = CallByName Str.3 Inspect.299 Inspect.295;
|
||||
ret Inspect.318;
|
||||
|
||||
procedure Inspect.64 (Inspect.302):
|
||||
ret Inspect.302;
|
||||
procedure Inspect.64 (Inspect.301):
|
||||
ret Inspect.301;
|
||||
|
||||
procedure Str.3 (#Attr.2, #Attr.3):
|
||||
let Str.246 : Str = lowlevel StrConcat #Attr.2 #Attr.3;
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
app "test" provides [main] to "./platform"
|
||||
|
||||
Op := U8 implements [Inspect { toInspector: myToInspector }]
|
||||
Op := U8 implements [Inspect { to_inspector: myToInspector }]
|
||||
|
||||
myToInspector : Op -> Inspector f where f implements InspectFormatter
|
||||
myToInspector = \@Op num -> Inspect.u8 num
|
||||
|
||||
main = Inspect.toInspector (@Op 1u8) |> Inspect.apply (Inspect.init {})
|
||||
# ^^^^^^^^^^^^^^^^^^^ Op#Inspect.toInspector(2): Op -[[myToInspector(2)]]-> Inspector f where f implements InspectFormatter
|
||||
main = Inspect.to_inspector (@Op 1u8) |> Inspect.apply (Inspect.init {})
|
||||
# ^^^^^^^^^^^^^^^^^^^^ Op#Inspect.to_inspector(2): Op -[[myToInspector(2)]]-> Inspector f where f implements InspectFormatter
|
||||
|
|
|
@ -2,5 +2,5 @@ app "test" provides [main] to "./platform"
|
|||
|
||||
Op := U8 implements [Inspect]
|
||||
|
||||
main = Inspect.toInspector (@Op 1u8) |> Inspect.apply (Inspect.init {})
|
||||
# ^^^^^^^^^^^^^^^^^^^ Op#Inspect.toInspector(3): Op -[[#Op_toInspector(3)]]-> Inspector f where f implements InspectFormatter
|
||||
main = Inspect.to_inspector (@Op 1u8) |> Inspect.apply (Inspect.init {})
|
||||
# ^^^^^^^^^^^^^^^^^^^^ Op#Inspect.to_inspector(3): Op -[[#Op_to_inspector(3)]]-> Inspector f where f implements InspectFormatter
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
app "test" provides [main] to "./platform"
|
||||
|
||||
main = Inspect.toInspector 7 |> Inspect.apply (Inspect.init {})
|
||||
# ^^^^^^^^^^^^^^^^^^^ Inspect#Inspect.toInspector(32): I64 -[[] + f:Inspect.i64(24):1]-> Inspector f where f implements InspectFormatter
|
||||
main = Inspect.to_inspector 7 |> Inspect.apply (Inspect.init {})
|
||||
# ^^^^^^^^^^^^^^^^^^^^ Inspect#Inspect.to_inspector(32): I64 -[[] + f:Inspect.i64(24):1]-> Inspector f where f implements InspectFormatter
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
app "test" provides [main] to "./platform"
|
||||
|
||||
main = Inspect.toInspector { a: "" } |> Inspect.apply (Inspect.init {})
|
||||
# ^^^^^^^^^^^^^^^^^^^ Inspect#Inspect.toInspector(32): { a : Str } -[[#Derived.toInspector_{a}(0)]]-> Inspector f where f implements InspectFormatter
|
||||
main = Inspect.to_inspector { a: "" } |> Inspect.apply (Inspect.init {})
|
||||
# ^^^^^^^^^^^^^^^^^^^^ Inspect#Inspect.to_inspector(32): { a : Str } -[[#Derived.to_inspector_{a}(0)]]-> Inspector f where f implements InspectFormatter
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
app "test" provides [main] to "./platform"
|
||||
|
||||
Op := U8 implements [Inspect { toInspector: myToInspector }]
|
||||
Op := U8 implements [Inspect { to_inspector: myToInspector }]
|
||||
|
||||
myToInspector : Op -> Inspector f where f implements InspectFormatter
|
||||
myToInspector = \@Op num -> Inspect.u8 num
|
||||
|
||||
main = Inspect.toInspector { op: @Op 1u8 } |> Inspect.apply (Inspect.init {})
|
||||
# ^^^^^^^^^^^^^^^^^^^ Inspect#Inspect.toInspector(32): { op : Op } -[[#Derived.toInspector_{op}(0)]]-> Inspector f where f implements InspectFormatter
|
||||
main = Inspect.to_inspector { op: @Op 1u8 } |> Inspect.apply (Inspect.init {})
|
||||
# ^^^^^^^^^^^^^^^^^^^^ Inspect#Inspect.to_inspector(32): { op : Op } -[[#Derived.to_inspector_{op}(0)]]-> Inspector f where f implements InspectFormatter
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
app "test" provides [main] to "./platform"
|
||||
|
||||
main = Inspect.toInspector 7u8 |> Inspect.apply (Inspect.init {})
|
||||
# ^^^^^^^^^^^^^^^^^^^ Inspect#Inspect.toInspector(32): U8 -[[] + f:Inspect.u8(17):1]-> Inspector f where f implements InspectFormatter
|
||||
main = Inspect.to_inspector 7u8 |> Inspect.apply (Inspect.init {})
|
||||
# ^^^^^^^^^^^^^^^^^^^^ Inspect#Inspect.to_inspector(32): U8 -[[] + f:Inspect.u8(17):1]-> Inspector f where f implements InspectFormatter
|
||||
|
|
|
@ -5,5 +5,5 @@ N := U8 implements [Decoding]
|
|||
|
||||
main : Decoder N _
|
||||
main = Decode.custom \bytes, fmt ->
|
||||
Decode.decodeWith bytes Decode.decoder fmt
|
||||
# ^^^^^^^^^^^^^^ N#Decode.decoder(3): List U8, fmt -[[7]]-> { rest : List U8, result : [Err [TooShort], Ok U8] } where fmt implements DecoderFormatting
|
||||
Decode.decode_with bytes Decode.decoder fmt
|
||||
# ^^^^^^^^^^^^^^ N#Decode.decoder(3): List U8, fmt -[[7]]-> { rest : List U8, result : [Err [TooShort], Ok U8] } where fmt implements DecoderFormatting
|
||||
|
|
|
@ -2,5 +2,5 @@ app "test" provides [main] to "./platform"
|
|||
|
||||
N := U8 implements [Encoding]
|
||||
|
||||
main = Encode.toEncoder (@N 15)
|
||||
# ^^^^^^^^^^^^^^^^ N#Encode.toEncoder(3): N -[[#N_toEncoder(3)]]-> Encoder fmt where fmt implements EncoderFormatting
|
||||
main = Encode.to_encoder (@N 15)
|
||||
# ^^^^^^^^^^^^^^^^^ N#Encode.to_encoder(3): N -[[#N_to_encoder(3)]]-> Encoder fmt where fmt implements EncoderFormatting
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
app "test" provides [main] to "./platform"
|
||||
|
||||
Trivial := {} implements [Eq {isEq}]
|
||||
Trivial := {} implements [Eq {is_eq}]
|
||||
|
||||
isEq = \@Trivial {}, @Trivial {} -> Bool.true
|
||||
is_eq = \@Trivial {}, @Trivial {} -> Bool.true
|
||||
|
||||
main = Bool.isEq (@Trivial {}) (@Trivial {})
|
||||
# ^^^^^^^^^ Trivial#Bool.isEq(2): Trivial, Trivial -[[isEq(2)]]-> Bool
|
||||
main = Bool.is_eq (@Trivial {}) (@Trivial {})
|
||||
# ^^^^^^^^^^ Trivial#Bool.is_eq(2): Trivial, Trivial -[[is_eq(2)]]-> Bool
|
||||
|
|
|
@ -2,5 +2,5 @@ app "test" provides [main] to "./platform"
|
|||
|
||||
N := U8 implements [Eq]
|
||||
|
||||
main = Bool.isEq (@N 15) (@N 23)
|
||||
# ^^^^^^^^^ N#Bool.isEq(3): N, N -[[#N_isEq(3)]]-> Bool
|
||||
main = Bool.is_eq (@N 15) (@N 23)
|
||||
# ^^^^^^^^^^ N#Bool.is_eq(3): N, N -[[#N_is_eq(3)]]-> Bool
|
||||
|
|
|
@ -2,4 +2,4 @@ app "test" provides [main] to "./platform"
|
|||
|
||||
main =
|
||||
\h -> Hash.hash h 7
|
||||
# ^^^^^^^^^ Hash#Hash.hash(1): a, I64 -[[Hash.hashI64(13)]]-> a where a implements Hasher
|
||||
# ^^^^^^^^^ Hash#Hash.hash(1): a, I64 -[[Hash.hash_i64(13)]]-> a where a implements Hasher
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
app "test"
|
||||
imports [Encode.{ toEncoder }]
|
||||
imports [Encode.{ to_encoder }]
|
||||
provides [main] to "./platform"
|
||||
|
||||
main = toEncoder { a: "" }
|
||||
# ^^^^^^^^^ Encoding#toEncoder(2): { a : Str } -[[#Derived.toEncoder_{a}(0)]]-> Encoder fmt where fmt implements EncoderFormatting
|
||||
main = to_encoder { a: "" }
|
||||
# ^^^^^^^^^^ Encoding#to_encoder(2): { a : Str } -[[#Derived.to_encoder_{a}(0)]]-> Encoder fmt where fmt implements EncoderFormatting
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
app "test"
|
||||
imports [Encode.{ toEncoder, custom }]
|
||||
imports [Encode.{ to_encoder, custom }]
|
||||
provides [main] to "./platform"
|
||||
|
||||
A := {} implements [Encoding {toEncoder}]
|
||||
toEncoder = \@A _ -> custom \b, _ -> b
|
||||
A := {} implements [Encoding {to_encoder}]
|
||||
to_encoder = \@A _ -> custom \b, _ -> b
|
||||
|
||||
main = toEncoder { a: @A {} }
|
||||
# ^^^^^^^^^ Encoding#toEncoder(2): { a : A } -[[#Derived.toEncoder_{a}(0)]]-> Encoder fmt where fmt implements EncoderFormatting
|
||||
main = to_encoder { a: @A {} }
|
||||
# ^^^^^^^^^^ Encoding#to_encoder(2): { a : A } -[[#Derived.to_encoder_{a}(0)]]-> Encoder fmt where fmt implements EncoderFormatting
|
||||
|
|
|
@ -7,6 +7,6 @@ main =
|
|||
s2 : Set Str
|
||||
s2 = Set.empty {}
|
||||
|
||||
Bool.isEq s1 s1 && Bool.isEq s2 s2
|
||||
# ^^^^^^^^^ Set#Bool.isEq(31): Set Str, Set Str -[[Set.isEq(31)]]-> Bool
|
||||
# ^^^^^^^^^ Set#Bool.isEq(31): Set U8, Set U8 -[[Set.isEq(31)]]-> Bool
|
||||
Bool.is_eq s1 s1 && Bool.is_eq s2 s2
|
||||
# ^^^^^^^^^^ Set#Bool.is_eq(31): Set Str, Set Str -[[Set.is_eq(31)]]-> Bool
|
||||
# ^^^^^^^^^^ Set#Bool.is_eq(31): Set U8, Set U8 -[[Set.is_eq(31)]]-> Bool
|
||||
|
|
|
@ -42,4 +42,4 @@ parseInput = \{} ->
|
|||
] is
|
||||
_ -> ""
|
||||
|
||||
main = Bool.isEq (parseInput {}) ""
|
||||
main = Bool.is_eq (parseInput {}) ""
|
|
@ -20,6 +20,6 @@ main =
|
|||
printed = printCombinatorParser f.parser
|
||||
if Bool.false then printed else "foo"
|
||||
|> List.first
|
||||
|> Result.withDefault ("foo")
|
||||
|> Result.with_default ("foo")
|
||||
|
||||
printCombinatorParser (Record [])
|
||||
|
|
|
@ -5,7 +5,7 @@ Parser a : List U8 -> List [Pair a (List U8)]
|
|||
any: Parser U8
|
||||
any = \inp ->
|
||||
when List.first inp is
|
||||
Ok u -> [Pair u (List.dropFirst inp 1)]
|
||||
Ok u -> [Pair u (List.drop_first inp 1)]
|
||||
_ -> []
|
||||
|
||||
main = any
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
app "test" provides [main] to "./platform"
|
||||
|
||||
entry =
|
||||
if Bool.true then List.first [] else Str.toI64 ""
|
||||
if Bool.true then List.first [] else Str.to_i64 ""
|
||||
|
||||
main = entry
|
||||
# ^^^^^ Result I64 [InvalidNumStr, ListWasEmpty]w_a
|
||||
|
|
|
@ -13,7 +13,7 @@ Id := U64 implements [MHash {hash, hash32}, Ord {eq, le}]
|
|||
hash = \@Id n -> n
|
||||
#^^^^{-1} Id#hash(7): Id -[[hash(7)]]-> U64
|
||||
|
||||
hash32 = \@Id n -> Num.toU32 n
|
||||
hash32 = \@Id n -> Num.to_u32 n
|
||||
#^^^^^^{-1} Id#hash32(8): Id -[[hash32(8)]]-> U32
|
||||
|
||||
eq = \@Id m, @Id n -> m == n
|
||||
|
|
|
@ -9,5 +9,5 @@ Id := U64 implements [MHash {hash, hash32}]
|
|||
hash = \@Id n -> n
|
||||
#^^^^{-1} Id#hash(4): Id -[[hash(4)]]-> U64
|
||||
|
||||
hash32 = \@Id n -> Num.toU32 n
|
||||
hash32 = \@Id n -> Num.to_u32 n
|
||||
#^^^^^^{-1} Id#hash32(5): Id -[[hash32(5)]]-> U32
|
||||
|
|
|
@ -39,7 +39,7 @@ encodeF32 = \_n -> encodeNothing
|
|||
encodeF64 = \_n -> encodeNothing
|
||||
encodeDec = \_n -> encodeNothing
|
||||
encodeBool = \_b -> encodeNothing
|
||||
encodeString = \str -> Encode.custom \bytes, @OnlyStrEncoder {} -> List.concat bytes (Str.toUtf8 str)
|
||||
encodeString = \str -> Encode.custom \bytes, @OnlyStrEncoder {} -> List.concat bytes (Str.to_utf8 str)
|
||||
encodeList : List elem, (elem -> Encoder OnlyStrEncoder) -> Encoder OnlyStrEncoder
|
||||
encodeList = \_lst, _encodeElem -> encodeNothing
|
||||
encodeRecord : List {key: Str, value: Encoder OnlyStrEncoder} -> Encoder OnlyStrEncoder
|
||||
|
@ -50,15 +50,15 @@ encodeTag : Str, List (Encoder OnlyStrEncoder) -> Encoder OnlyStrEncoder
|
|||
encodeTag = \_name, _payload -> encodeNothing
|
||||
|
||||
|
||||
HelloWorld := {} implements [Encoding {toEncoder}]
|
||||
HelloWorld := {} implements [Encoding {to_encoder}]
|
||||
|
||||
toEncoder = \@HelloWorld {} ->
|
||||
to_encoder = \@HelloWorld {} ->
|
||||
Encode.custom \bytes, fmt ->
|
||||
bytes
|
||||
|> Encode.appendWith (Encode.string "Hello, World!\n") fmt
|
||||
|> Encode.append_with (Encode.string "Hello, World!\n") fmt
|
||||
|
||||
f =
|
||||
when Str.fromUtf8 (Encode.toBytes (@HelloWorld {}) (@OnlyStrEncoder {})) is
|
||||
when Str.from_utf8 (Encode.to_bytes (@HelloWorld {}) (@OnlyStrEncoder {})) is
|
||||
Ok s -> s
|
||||
_ -> "<bad>"
|
||||
|
||||
|
|
|
@ -2,9 +2,9 @@ app "test" provides [main] to "./platform"
|
|||
|
||||
entry =
|
||||
{
|
||||
toF32: Num.toF32,
|
||||
toF64: Num.toF64,
|
||||
to_f32: Num.to_f32,
|
||||
to_f64: Num.to_f64,
|
||||
}
|
||||
|
||||
main = entry
|
||||
# ^^^^^ { toF32 : Num * -[[Num.toF32(139)]]-> F32, toF64 : Num w_a -[[Num.toF64(141)]]-> F64 }
|
||||
# ^^^^^ { to_f32 : Num * -[[Num.to_f32(139)]]-> F32, to_f64 : Num w_a -[[Num.to_f64(141)]]-> F64 }
|
||||
|
|
|
@ -2,17 +2,17 @@ app "test" provides [main] to "./platform"
|
|||
|
||||
entry =
|
||||
{
|
||||
toI8: Num.toI8,
|
||||
toI16: Num.toI16,
|
||||
toI32: Num.toI32,
|
||||
toI64: Num.toI64,
|
||||
toI128: Num.toI128,
|
||||
toU8: Num.toU8,
|
||||
toU16: Num.toU16,
|
||||
toU32: Num.toU32,
|
||||
toU64: Num.toU64,
|
||||
toU128: Num.toU128,
|
||||
to_i8: Num.to_i8,
|
||||
to_i16: Num.to_i16,
|
||||
to_i32: Num.to_i32,
|
||||
to_i64: Num.to_i64,
|
||||
to_i128: Num.to_i128,
|
||||
to_u8: Num.to_u8,
|
||||
to_u16: Num.to_u16,
|
||||
to_u32: Num.to_u32,
|
||||
to_u64: Num.to_u64,
|
||||
to_u128: Num.to_u128,
|
||||
}
|
||||
|
||||
main = entry
|
||||
# ^^^^^ { toI128 : Int * -[[Num.toI128(125)]]-> I128, toI16 : Int w_a -[[Num.toI16(119)]]-> I16, toI32 : Int w_b -[[Num.toI32(121)]]-> I32, toI64 : Int w_c -[[Num.toI64(123)]]-> I64, toI8 : Int w_d -[[Num.toI8(117)]]-> I8, toU128 : Int w_e -[[Num.toU128(135)]]-> U128, toU16 : Int w_f -[[Num.toU16(129)]]-> U16, toU32 : Int w_g -[[Num.toU32(131)]]-> U32, toU64 : Int w_h -[[Num.toU64(133)]]-> U64, toU8 : Int w_i -[[Num.toU8(127)]]-> U8 }
|
||||
# ^^^^^ { to_i128 : Int * -[[Num.to_i128(125)]]-> I128, to_i16 : Int w_a -[[Num.to_i16(119)]]-> I16, to_i32 : Int w_b -[[Num.to_i32(121)]]-> I32, to_i64 : Int w_c -[[Num.to_i64(123)]]-> I64, to_i8 : Int w_d -[[Num.to_i8(117)]]-> I8, to_u128 : Int w_e -[[Num.to_u128(135)]]-> U128, to_u16 : Int w_f -[[Num.to_u16(129)]]-> U16, to_u32 : Int w_g -[[Num.to_u32(131)]]-> U32, to_u64 : Int w_h -[[Num.to_u64(133)]]-> U64, to_u8 : Int w_i -[[Num.to_u8(127)]]-> U8 }
|
||||
|
|
|
@ -1405,7 +1405,7 @@ pub fn can_problem<'b>(
|
|||
)]),
|
||||
alloc.tip().append(
|
||||
alloc.reflow(
|
||||
"An expression like `4`, `\"hello\"`, or `functionCall MyThing` is like `return 4` in other programming languages. To me, it seems like you did `return 4` followed by more code in the lines after, that code would never be executed!"
|
||||
"An expression like `4`, `\"hello\"`, or `function_call(MyThing)` is like `return 4` in other programming languages. To me, it seems like you did `return 4` followed by more code in the lines after, that code would never be executed!"
|
||||
)
|
||||
),
|
||||
alloc.tip().append(
|
||||
|
@ -1426,7 +1426,7 @@ pub fn can_problem<'b>(
|
|||
alloc.region(lines.convert_region(region), severity),
|
||||
alloc.reflow("Add an exclamation mark at the end, like:"),
|
||||
alloc
|
||||
.parser_suggestion("{ readFile!: Str => Str }")
|
||||
.parser_suggestion("{ read_file!: Str => Str }")
|
||||
.indent(4),
|
||||
alloc.reflow("This will help readers identify it as a source of effects."),
|
||||
]);
|
||||
|
|
|
@ -436,7 +436,7 @@ pub fn type_problem<'b>(
|
|||
alloc.region(lines.convert_region(region), severity),
|
||||
alloc.reflow("Add an exclamation mark at the end, like:"),
|
||||
alloc
|
||||
.parser_suggestion("{ readFile! : File.read! }")
|
||||
.parser_suggestion("{ read_file! : File.read! }")
|
||||
.indent(4),
|
||||
alloc.reflow("This will help readers identify it as a source of effects."),
|
||||
];
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue