sweet interfaces
This is an experimental implementation of the ECMAScript first-class protocols proposal using Sweet.js.
Install
npm install @sweet-js/cli sweet-interfaces
Use
Import class
, protocol
, and implements
from the sweet-interfaces
packages:
'lang sweet.js';;;
and compile with Sweet:
sjs functor.js
Sample Output
Input:
'lang sweet.js';; protocol Foldable foldr; { return thisFoldablefoldr a ; } { return thisFoldablefoldr m + 1 0; } { return thisFoldablefoldr m || false ; } implements Foldable { thishead = head; thistail = tail; } { if thistail != null memo = thistailFoldablefoldrf memo; return ; } let a = 1 null;let b = 0 a; console;console;
Output:
const Foldable_297 = { return name: "Foldable" extends: _extends_300 symbols: foldr: Symbol"Foldable.foldr" staticSymbols: {} protoProperties: Object staticProperties: Object ;} 0; { thishead = head_309; thistail = tail_310; } { if thistail != null memo_312 = thistailFoldable_297foldrf_311 memo_312; return ; } Protocol; let a_298 = 1 null;let b_299 = 0 a_298;console;console;