Update rfcs/generic-functions.md

Co-authored-by: Tiffany Bennett <tiffany@tiffnix.com>
This commit is contained in:
Alan Jeffrey 2021-05-06 09:09:10 -05:00 committed by GitHub
parent e73e104257
commit a01935e96a
Signed by: DevComp
GPG key ID: 4AEE18F83AFDEB23

View file

@ -8,7 +8,7 @@ Extend the syntax and semantics of functions to support explicit generic functio
Currently Luau allows generic functions to be inferred but not given explicit type annotations. For example Currently Luau allows generic functions to be inferred but not given explicit type annotations. For example
``` ```lua
function id(x) return x end function id(x) return x end
local x: string = id("hi") local x: string = id("hi")
local y: number = id(37) local y: number = id(37)
@ -107,4 +107,4 @@ We did originally consider Rank-1 types, but the problem is that's not backward-
We could introduce syntax for generic types without changing the semantics, but then there'd be a gap between the syntax (where the types `() -> <a>(a) -> a` and `<a>() -> (a) -> a` are different) and the semantics (where they are not). As noted above, this isn't sound. We could introduce syntax for generic types without changing the semantics, but then there'd be a gap between the syntax (where the types `() -> <a>(a) -> a` and `<a>() -> (a) -> a` are different) and the semantics (where they are not). As noted above, this isn't sound.
Rather than using Rank-N types, we could use SML-style polymorphism, but this would need something like the [value restriction](http://users.cis.fiu.edu/~smithg/cop4555/valrestr.html) to be sound. Rather than using Rank-N types, we could use SML-style polymorphism, but this would need something like the [value restriction](http://users.cis.fiu.edu/~smithg/cop4555/valrestr.html) to be sound.