Quantcast
Channel: ReScript Forum - Latest posts
Viewing all articles
Browse latest Browse all 2592

Confusion regarding generic type function definition inside of another function

$
0
0

I must say I don’t understand what you mean

Type variables are scoped to the top level definition so by naming it you are forcing it to take on a single type for each invocation of the top level function.

the top level function in question is main(), so with each main() invocation, I only get one type of 'a ? then why does the trace function defined in global scope work? wouldn’t it just be 1 type 'a for the main invocation as well?

Also, why the trace function when defined inside main scope without 'a type for x work ?

let main = ()=>{
  let trace = (x, b: string) => {
    Js.logMany([String.make(x), b])
    x
  }
  //....
}

I read the Doc and it says

Scoped Polymorphic Types in ReScript are functions with the capability to handle arguments of any type within a specific scope

Does this imply that global scope is not a “specific scope”? (Because you didn’t need to use the Scoped Polymorphic type syntax for functions that are defined in global scope, for it to be polymorphic)
I don’t understand anything :frowning:


Viewing all articles
Browse latest Browse all 2592

Trending Articles