rbbarbosa / Petit

Petit programming language and compiler
BSD 3-Clause "New" or "Revised" License
9 stars 1 forks source link

function type inference #10

Closed rbbarbosa closed 5 hours ago

rbbarbosa commented 6 hours ago

Type inference for recursive functions can be challenging:

factorial(integer n) = if n then n * factorial(n-1) else 1

When factorial(n-1) is called, the type may only be no_type at that point. Then, the result of using a no_type operand must be promoted to the other operand's type. So, integer_type * no_type results in integer_type.

rbbarbosa commented 5 hours ago

Reasonable fix in this commit