Skip to content

Instantly share code, notes, and snippets.

@davehughes
Last active July 16, 2018 13:44
Show Gist options
  • Save davehughes/d188050d316a77e367939b96272deaf4 to your computer and use it in GitHub Desktop.
Save davehughes/d188050d316a77e367939b96272deaf4 to your computer and use it in GitHub Desktop.
Zion generic function application example
module _
fn square(x any T) any T {
return x * x
}
fn apply(f (fn(y any T) any T), x any T) any T {
return f(x)
}
fn main() {
print(apply(square, 2))
}
program.zion:3:4: error: we don't have enough info to instantiate this function
program.zion:11:4: while checking main : fn _() ()
program.zion:11:4: error: failures encountered
@wbbradley
Copy link

wbbradley commented Jul 16, 2018

The issue here is that square is not yet reified as a bound variable, so at the point that the reference to square is made on line 12, the compiler doesn't know how to instantiate it. This is either a weakness in the language or the compiler, I think the compiler. The deeper issue is the resolution of function definitions as symbols in the context of an expression evaluation. You should try to come up with a way to do the book keeping to allow unchecked functions (basically any function definition with free type variables) to be treated like function literals are treated. Then I bet this would just work. https://github.com/zionlang/zion/blob/master/src/type_checker.cpp#L1000

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment