Skip to content

Instantly share code, notes, and snippets.

@nyinyithann
Created November 26, 2022 19:56
Show Gist options
  • Save nyinyithann/3770f73e66e9a612e153b81c8ed0811c to your computer and use it in GitHub Desktop.
Save nyinyithann/3770f73e66e9a612e153b81c8ed0811c to your computer and use it in GitHub Desktop.
GADT ReScript
%%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