Page MenuHomePhorge

test_tco_monad.js
No OneTemporary

Size
508 B
Referenced Files
None
Subscribers
None

test_tco_monad.js

// Monad-style bind chain (simplified newt pattern)
const MkM = h1 => ({ tag: 0, h1: h1 });
const bind = (m, f) =>
MkM(tc => eta => {
const sc = m.h1(tc)(eta);
if (sc.tag === 1) return f(sc.h2.h3).h1(sc.h2.h2)(eta);
return sc;
});
const pure = v => MkM(tc => eta => ({ tag: 1, h2: { h2: tc, h3: v } }));
let chain = pure(0);
for (let i = 0; i < 800; i++) {
chain = bind(chain, v => pure(v + 1));
}
const result = chain.h1({})(0);
console.log('monad chain result:', result.h2.h3); // 100

File Metadata

Mime Type
text/plain
Expires
Wed, Jun 17, 12:20 PM (15 h, 53 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
573158
Default Alt Text
test_tco_monad.js (508 B)

Event Timeline