Created
November 26, 2022 19:56
-
-
Save nyinyithann/3770f73e66e9a612e153b81c8ed0811c to your computer and use it in GitHub Desktop.
GADT ReScript
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
%%raw( | |
"/* | |
* this js function will work under both [string] and [float] | |
*/ | |
function add (x,y){ | |
return x + y; | |
}") | |
type rec t<_> = | String : t<string> | Float : t<float> | |
external add : (@ignore t<'a>, 'a, 'a) => 'a = "add" | |
Js.log(add(String, "abc", "def")) | |
Js.log(add(Float, 1. , 2.)) | |
@unboxed | |
type rec k = Any('a) : k | |
external add: (k, k) => k = "add" | |
Js.log(add(Any("a"), Any("b"))) | |
Js.log(add(Any(10), Any(20))) | |
Js.log(add(Any(10.1), Any(20.1))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment