mirror of
https://github.com/roc-lang/roc.git
synced 2025-10-01 15:51:12 +00:00
implement Num.compare
This commit is contained in:
parent
4c995b12a6
commit
1b42831973
8 changed files with 225 additions and 2 deletions
|
@ -317,6 +317,12 @@ pub fn types() -> MutMap<Symbol, (SolvedType, Region)> {
|
|||
// isGte or (>=) : Num a, Num a -> Bool
|
||||
add_num_comparison(Symbol::NUM_GTE);
|
||||
|
||||
// compare : Num a, Num a -> [ LT, EQ, GT ]
|
||||
add_type(Symbol::NUM_COMPARE, {
|
||||
let_tvars! { u, v, w, num };
|
||||
unique_function(vec![num_type(u, num), num_type(v, num)], ordering_type(w))
|
||||
});
|
||||
|
||||
// toFloat : Num a -> Float
|
||||
add_type(Symbol::NUM_TO_FLOAT, {
|
||||
let_tvars! { star1, star2, a };
|
||||
|
@ -1205,3 +1211,22 @@ fn map_type(u: VarId, key: VarId, value: VarId) -> SolvedType {
|
|||
],
|
||||
)
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
fn ordering_type(u: VarId) -> SolvedType {
|
||||
// [ LT, EQ, GT ]
|
||||
SolvedType::Apply(
|
||||
Symbol::ATTR_ATTR,
|
||||
vec![
|
||||
flex(u),
|
||||
SolvedType::TagUnion(
|
||||
vec![
|
||||
(TagName::Global("GT".into()), vec![]),
|
||||
(TagName::Global("EQ".into()), vec![]),
|
||||
(TagName::Global("LT".into()), vec![]),
|
||||
],
|
||||
Box::new(SolvedType::EmptyTagUnion),
|
||||
),
|
||||
],
|
||||
)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue