Syntax Lookup
Enter some language construct you want to know more about.
This is a scoped polymorphic type.
In ReScript, polymorphic functions can only deal with one specific type. When they are called, their type gets fixed.
For instance this logging function is bound in a polymorphic way as you can see by the type parameter ('a
).
REStype logger<'a> = { log: 'a => unit}
@module("jsAPI") external getLogger: unit => logger<'a> = "getLogger"
let myLogger = getLogger()
myLogger.log("Hello, ReScript!")
myLogger.log(42) // Type error!
Scoped polymorphic types make such behavior possible, in a type-safe way. See the 'a.
in the example below.