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

Non top-level polymorphic type (aka 'a. notation)

$
0
0

Hello there !

For my FRP library, I need to have a function that create a truly polymorphic function (the proxy wrapper).

But the problem is that the created functions are monomorphic and cannot be reused on different types (as they should) to share the observing context.

let tilia: unit => 'a => 'a = () => {
   // setup context
   proxify(context, ...)
}

// Usage
let connect = tilia()

let a = connect({ firstname: "Ada", lastName: "Byron" }) // Ok, a now looks like a regular "person"

let b = connect({ title: "About math and foly" }) // Not ok: This record expression is expected to have type person

This is really a show-stopper for the “forest” feature where you can create trees that share observing state…

Are there any solutions to this problem ? Has anyone had the same need and how was it solved ?

Thank you

PS: I found this solution but I would prefer to have a polymorphic function if possible…

type person = {name: string}
type article = {title: string}

// explicit context solution
let root = tilia()
// top-level function to avoid scoped polymorphism problem
let user = connect(root, {name: "Alice"})
let post = connect(root, {title: "Hello"})

Viewing all articles
Browse latest Browse all 2592

Trending Articles