Last active
July 16, 2018 13:44
-
-
Save davehughes/d188050d316a77e367939b96272deaf4 to your computer and use it in GitHub Desktop.
Zion generic function application example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The issue here is that
square
is not yet reified as abound
variable, so at the point that the reference tosquare
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