Guide
Exp vs Effect-TS
Every core capability that motivates Effect-TS — exact typed errors, DI layers, scoped resource cleanup, structured concurrency, and virtual clocks — delivered at compile time with 29× faster V8 runtime and 0.042× gzipped bundle size.
Feature-by-feature parity matrix
| Capability | Effect-TS (Runtime Monad) | Exp (Compile-Time Effects) |
|---|---|---|
| Typed errors & narrowing | Data.TaggedError + Effect.fail + Effect.catchTags | Fail<T[A | B]> with automatic constructor subtraction; 0 new Error() allocs |
| Errors vs defects | Typed E channel vs Effect.die / Cause | Fail<E> row vs untyped defects (panic, assert, bounds, overflow) |
| Dependency injection | Context.Tag + Layer.effect + Layer.provide (runtime Map) | effect + handler + use handle H1, H2 (compile-time Kahn topological sort) |
| Resource cleanup | Effect.acquireRelease + Effect.scoped | Affine fn T.close(self) + defer lowered to lexical LIFO try/finally |
| Structured concurrency | Effect.all, Effect.race, Effect.retry, Effect.timeoutOption | Colorless Async.scope, row-mapped Async.all, race, retry, timeout, Semaphore, Channel |
| Flat composition | Effect.gen(function* () { yield* ... }) / .pipe(...) | Direct sequential statements + use flattening — zero generators or pipes |
| Deterministic timers | TestClock.adjust(...) | Built-in virtual clock in exp test advancing instantaneously to timer deadlines |
| Pure code runtime cost | Effect runtime & fiber interpreter (~79 KB gz) | 0 bytes runtime for pure modules; ≤ 3 KB gz when every feature is used |
Side-by-side: DI, typed errors & scopes
Compare idiomatic Exp (no generators, no yield*, no manual
Layer.mergeAll, and exact constructor-level inference) against equivalent
Effect-TS 3.x:
type UserError
InvalidId(Int)
NotFound(Int)
Banned(String)
end
effect Database
queryUser(id: Int) -> { id: Int, name: String } ! {Fail<UserError[NotFound | Banned]>}
end
effect Logger
info(msg: String) -> Unit
end
fn loadUser(id: Int)
if id <= 0 then fail(InvalidId(id)) end
user = Database.queryUser(id)
Logger.info("loaded {user.name}")
user
end
fn loadOrGuest(id: Int)
handle loadUser(id) with
fn Fail.raise(InvalidId(_) | NotFound(_)) { id: 0, name: "guest" } end
fn Fail.raise(Banned(why)) { id: 0, name: "banned:{why}" } end
end
end
handler TestDb: Database
fn queryUser(id)
if id == 1 then { id: 1, name: "Ada" } else fail(NotFound(id)) end
end
end
handler QuietLog: Logger
fn info(_) () end
end
fn main()
use handle TestDb, QuietLog
u1 = loadOrGuest(1)
u2 = loadOrGuest(99)
print("{u1.name}, {u2.name}")
end
Hover or focus any symbol to inspect inferred types, effects, and errors Effect-TS 3.x — runtime Tag/Layer + generator wrappers ts import { Context, Data, Effect, Layer } from "effect";
class InvalidId extends Data.TaggedError("InvalidId")<{ id: number }> {}
class NotFound extends Data.TaggedError("NotFound")<{ id: number }> {}
class Banned extends Data.TaggedError("Banned")<{ reason: string }> {}
class Database extends Context.Tag("Database")<Database, {
readonly queryUser: (id: number) => Effect.Effect<{ id: number; name: string }, NotFound | Banned>;
}>() {}
class Logger extends Context.Tag("Logger")<Logger, {
readonly info: (msg: string) => Effect.Effect<void>;
}>() {}
const loadUser = (id: number) =>
Effect.gen(function* () {
if (id <= 0) return yield* Effect.fail(new InvalidId({ id }));
const db = yield* Database;
const log = yield* Logger;
const user = yield* db.queryUser(id);
yield* log.info(`loaded ${user.name}`);
return user;
});
const loadOrGuest = (id: number) =>
loadUser(id).pipe(
Effect.catchTags({
InvalidId: () => Effect.succeed({ id: 0, name: "guest" }),
NotFound: () => Effect.succeed({ id: 0, name: "guest" }),
Banned: (e) => Effect.succeed({ id: 0, name: `banned:${e.reason}` }),
})
);
Why Exp is 29× faster & 24× smaller
Effect-TS achieves remarkable safety within TypeScript's constraints by interpreting a runtime
fiber/monad AST over JavaScript generators, runtime Context service maps, and
Exit/Cause allocations on every step. Because Exp owns the type
checker and compiler:
- Zero fiber interpreter: pure and service-handler code lowers straight to plain V8/JSC functions with zero thunk or generator-frame allocation.
- Static handler specialization:
handle ... with resolves the DI graph at compile time and passes capabilities as direct arguments or inlines calls completely. - Native control flow:
for loops, early return, and defer lower to native JS loops and try/finally rather than monadic combinator chains. - Sync/async specialization: synchronous callers of polymorphic helpers emit plain sync JS with zero
Promise creation or microtask scheduling.
Verified B5 benchmark breakdown
Metric (B5 Parity Suite) effect@3.22.5 Exp Ratio (Exp / Effect-TS) Budget Wall time (pinned V8, Node 24) 1.000× 0.034× (29× faster) 0.034× ≤ 0.25× Wall time (pinned JSC, Bun 1.3) 1.000× 0.055× (18× faster) 0.055× ≤ 0.25× JS Heap allocations 1.00× 0.06× 0.06× ≤ 0.25× Gzipped bundle bytes 1.000× 0.042× (24× smaller) 0.042× ≤ 0.15×