Created
January 18, 2020 19:59
-
-
Save mlms13/558df648e0df4c6299d10fade04b5c10 to your computer and use it in GitHub Desktop.
Structural typing with first-class modules
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
// 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 */ |
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
let x = List.contains((module String.Eq), "a", ["b", "c", "d"]); | |
let y = List.contains((module String), "a", ["b", "c", "d"]); |
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
module type EQ = { | |
type t; | |
let eq: (t, t) => bool; | |
}; |
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
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)); | |
}; |
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
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