castToNat working

This commit is contained in:
Joshua Hoeflich 2021-08-18 11:31:48 -05:00
parent 92da003fba
commit b4f575736b
3 changed files with 151 additions and 20 deletions

View file

@ -4,8 +4,8 @@ use roc_module::symbol::Symbol;
use roc_region::all::Region;
use roc_types::builtin_aliases::{
bool_type, dict_type, float_type, i128_type, int_type, list_type, nat_type, num_type,
ordering_type, result_type, set_type, str_type, str_utf8_byte_problem_type, u32_type, u64_type,
u8_type, u16_type
ordering_type, result_type, set_type, str_type, str_utf8_byte_problem_type, u16_type, u32_type,
u64_type, u8_type,
};
use roc_types::solved_types::SolvedType;
use roc_types::subs::VarId;
@ -509,11 +509,17 @@ pub fn types() -> MutMap<Symbol, (SolvedType, Region)> {
);
// bytesToU16 : List U8, Nat -> U16
add_top_level_function_type!(
Symbol::NUM_BYTES_TO_U16,
vec![list_type(u8_type()), nat_type()],
Box::new(u16_type()),
);
{
let position_out_of_bounds = SolvedType::TagUnion(
vec![(TagName::Global("OutOfBounds".into()), vec![])],
Box::new(SolvedType::Wildcard),
);
add_top_level_function_type!(
Symbol::NUM_BYTES_TO_U16,
vec![list_type(u8_type()), nat_type()],
Box::new(result_type(u16_type(), position_out_of_bounds)),
);
}
// bytesToU32 : List U8, Nat -> U32
add_top_level_function_type!(