montylang / monty

Language from a parallel universe where Python is functional
https://montylang.github.io/docs/
BSD 3-Clause "New" or "Revised" License
5 stars 0 forks source link

Infer function types at compile time (or semantic-time currently) #30

Open elimirks opened 3 years ago

elimirks commented 3 years ago

To compile to LLVM or some other bytecode, we'll have to improve our inference.

For example:

def add(a, b):
  return (x): str(x) + "," + str(a + b)

x = add(3, 7)

y = x("hi")
# Generate def add(a: int, b: int) -> (str -> str):
z = x(3.14)
# Generate def add(a: int, b: int) -> (float -> str):

In the case where a function type cannot be inferred, it's considered a no-op.

e.g.

x = add(3,7)

This expression alone doesn't do anything, because the function returned by add and assigned to x is never used.