Skip to content

Commit

Permalink
Fix: polymorphic and concrete numeral types are now distinguished
Browse files Browse the repository at this point in the history
before:
> foo : (Foo String Int a)
> add_one : forall a. (Maybe I32 -> Maybe I32 can a)

after:
> foo : (Foo String (Int a))
> add_one : forall a. (Maybe I32 -> Maybe I32 can a) -- No change for concrete types

refs: #203 (comment)
  • Loading branch information
eldesh committed Nov 11, 2024
1 parent fc88982 commit afe8213
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions src/types/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -250,8 +250,24 @@ impl Type {
TypeBinding::Unbound(..) => TypePriority::MAX,
},
Function(_) => TypePriority::FUN,
TypeApplication(ctor, _) if ctor.is_polymorphic_int_type() => TypePriority::MAX,
TypeApplication(ctor, _) if ctor.is_polymorphic_float_type() => TypePriority::MAX,
TypeApplication(ctor, args) if ctor.is_polymorphic_int_type() => {
if matches!(cache.follow_typebindings_shallow(&args[0]), Type::TypeVariable(_)) {
// type variable is unbound variable
TypePriority::APP
} else {
// type variable is bound (polymorphic int)
TypePriority::MAX
}
},
TypeApplication(ctor, args) if ctor.is_polymorphic_float_type() => {
if matches!(cache.follow_typebindings_shallow(&args[0]), Type::TypeVariable(_)) {
// type variable is unbound variable
TypePriority::APP
} else {
// type variable is bound (polymorphic float)
TypePriority::MAX
}
},
TypeApplication(ctor, _) => {
if ctor.is_pair_type() {
TypePriority::PAIR
Expand Down

0 comments on commit afe8213

Please sign in to comment.