Skip to content

Instantly share code, notes, and snippets.

@mlms13
Created January 18, 2020 19:59
Show Gist options
  • Save mlms13/558df648e0df4c6299d10fade04b5c10 to your computer and use it in GitHub Desktop.
Save mlms13/558df648e0df4c6299d10fade04b5c10 to your computer and use it in GitHub Desktop.
Structural typing with first-class modules
// Generated by BUCKLESCRIPT, PLEASE EDIT WITH CARE
'use strict';
var List$Modules = require("./List.bs.js");
var String$Modules = require("./String.bs.js");
var x = List$Modules.contains(String$Modules.Eq, "a", /* :: */[
"b",
/* :: */[
"c",
/* :: */[
"d",
/* [] */0
]
]
]);
var y = List$Modules.contains({
eq: String$Modules.eq
}, "a", /* :: */[
"b",
/* :: */[
"c",
/* :: */[
"d",
/* [] */0
]
]
]);
exports.x = x;
exports.y = y;
/* x Not a pure module */
let x = List.contains((module String.Eq), "a", ["b", "c", "d"]);
let y = List.contains((module String), "a", ["b", "c", "d"]);
module type EQ = {
type t;
let eq: (t, t) => bool;
};
let contains =
(type a, eq: (module Interface.EQ with type t = a), x: a, xs: list(a))
: bool => {
module Eq = (val eq);
Belt.List.reduce(xs, false, (acc, curr) => acc || Eq.eq(curr, x));
};
type t = string;
let append = (++);
let eq = (a: string, b: string) => a == b;
let lte = (a: string, b: string) => a <= b;
let toUpperCase = Js.String.toUpperCase;
module Eq: Interface.EQ with type t = string = {
type t = string;
let eq = eq;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment