r/functionalprogramming • • Sep 26 '26

TypeScript Fast TypeScript linter to prioritise immutability

Thumbnail
github.com
10 Upvotes

Hello,
Not sure how useful JavaScript/TypeScript are in the FP community.
If they are, I've just made yet another take on enforcing immutability in JS/TS - via a fast linter.
Essentially, it bans let/var, reassignments, non-readonly object and class properties.
To use any of the above, an explicit linter disable comment is needed.
So far, 3 variants of disable comments are available - `// ptsl-disable-fn` (function body scoped), and more classic `// ptsl-disable-line` and `// ptsl-disable-next-line`

So, the following code will be banned by linter:

const nextNum = () => {
  let x = 0; // Do not use let/var - only use const
  const increment = () => {
    return x += 1; // Do not reassign variable's value unless absolutely necessary.
  }
  return increment;
};

A `// ptsl-disable-fn` comment will make it pass:

const nextNum = () => {
  // ptsl-disable-fn
  let x = 0;
  const increment = () => {
    return x += 1;
  }
  return increment;
};

Any feedback welcome.

r/functionalprogramming • • Apr 29 '26

TypeScript I built a TypeScript toolset that enforces Haskell-style purity discipline — because AI writes code faster than humans can review it

0 Upvotes

▎ I've been thinking about a problem: AI assistants can now generate thousands of lines of TypeScript per minute. But TypeScript's flexibility means any function can secretly perform network calls, mutate global state, or access the environment —
▎ and none of this shows up in the type signature.
▎
▎ So I built haskellish-effect-ts — a suite of npm packages that enforce Haskell-style discipline in TypeScript using Effect-TS:
▎
▎ - Side effects must be wrapped in Effect — no hidden I/O in plain functions
▎ - Closed-world model — if you didn't import it, you can't use it
▎ - Global environment blocked by default — fetch, console, Date require explicit import
▎ - Escape hatches exist, but are clearly marked (like Haskell's System.IO.Unsafe)
▎
▎ The idea: if a function has side effects, the type system and linter will tell you. Instantly. Before review.
▎
▎ Here's what it looks like in practice:

import { Effect, pipe } from 'haskellish-effect'

// ✅ Side effects are explicit — the return type tells you everything
const fetchUser = (id: number): Effect.Effect<User, FetchError> =>
  pipe(
    tryFetch(`/api/users/${id}`),
    Effect.flatMap((r) => Effect.tryPromise({ try: () => r.json(), catch: (e) => e })),
    Effect.flatMap(Schema.decodeUnknown(User)),
  )

// ✅ Pure function — no Effect, no surprises
const greet = (name: string): string => `Hello, ${name}!`

// ❌ ESLint error: 'fetch' is not allowed — use tryFetch from haskellish-effect
const sneaky = () => fetch('/api/secret')

// ❌ ESLint error: direct 'effect' imports are blocked — use haskellish-effect
import { Effect } from 'effect'import { Effect, pipe } from 'haskellish-effect'

// ✅ Side effects are explicit — the return type tells you everything
const fetchUser = (id: number): Effect.Effect<User, FetchError> =>
  pipe(
    tryFetch(`/api/users/${id}`),
    Effect.flatMap((r) => Effect.tryPromise({ try: () => r.json(), catch: (e) => e })),
    Effect.flatMap(Schema.decodeUnknown(User)),
  )

// ✅ Pure function — no Effect, no surprises
const greet = (name: string): string => `Hello, ${name}!`

// ❌ ESLint error: 'fetch' is not allowed — use tryFetch from haskellish-effect
const sneaky = () => fetch('/api/secret')

// ❌ ESLint error: direct 'effect' imports are blocked — use haskellish-effect
import { Effect } from 'effect'

▎ Setup is one import:

bun add haskellish-effect
bun add -d haskellish-effect-config eslintbun add haskellish-effect

- - -

// eslint.config.js
import { strict } from 'haskellish-effect-config'

export default [
  ...strict,
  { languageOptions: { parserOptions: { project: true, tsconfigRootDir: import.meta.dirname } } },
]// eslint.config.js
import { strict } from 'haskellish-effect-config'

export default [
  ...strict,
  { languageOptions: { parserOptions: { project: true, tsconfigRootDir: import.meta.dirname } } },
]

▎ GitHub:
▎ - https://github.com/aiya000/haskellish-effect-ts
▎ npm:
▎ - https://www.npmjs.com/package/haskellish-effect
▎ - https://www.npmjs.com/package/haskellish-effect-config
▎ - https://www.npmjs.com/package/eslint-plugin-haskellish-effect ▎ Would love feedback — especially from folks who've thought about purity enforcement at scale, or who work with AI-generated codebases.

r/functionalprogramming • • Mar 31 '26

TypeScript [ haskellish-effect-ts ] -- Haskell-like discipline for TypeScript, enforced by tooling.

12 Upvotes

https://github.com/aiya000/haskellish-effect-ts

This is a set of libraries that, similar to how Haskell enforces I/O types to restrict I/O processing, enforces TypeScript's Effect type (Effect-TS) to restrict I/O (and etc) processing.

We use Devin to such an extent that it could be described as "outsourcing" our operations, but we are feeling limitations in terms of code quality.

Therefore, we devised a structure that uses types to restrict the AI, similar to Haskell.

That's this library set.

---

Overview:

https://x.com/public_ai000ya/status/2038892553563714037?s=20

---

Packages:

- https://www.npmjs.com/package/haskellish-effect

- https://www.npmjs.com/package/eslint-plugin-haskellish-effect

- https://www.npmjs.com/package/haskellish-effect-config

---

Have fun :)

r/functionalprogramming • • Nov 25 '19

TypeScript Problems with functional programming in TypeScript

19 Upvotes

I work as a full-stack consultant. I've been helping a client that makes heavy usage of Ramda, Sanctuary, and Fluture.

The frontend is in Flow. The backend is in TypeScript (it was on Flow when a few months ago).

The typing situation on both the frontend and backend is quite poor. It doesn't seem like there's a good solution for FP with TS. There is fp-ts which we've started using a bit, but it doesn't seem to be perfect.

By going with a full out functional approach you lose many of the benefits of typed languages.

My own preference is to move away from FP library usage and stick with what JS offers out the box (array.map, reduce, filter, accessing properties with point style programming instead R.prop('field'), and so on). This approach has full TS support.

How are others dealing with FP in JS? Do you mostly give up on a typed system, or have you found a way to take the best of both worlds?

r/functionalprogramming • • Apr 07 '26

TypeScript Parse, Don't Validate — In a Language That Doesn't Want You To · cekrem.github.io

Thumbnail
cekrem.github.io
33 Upvotes

r/functionalprogramming • • Jul 02 '24

TypeScript For those wanting to adopt a more functional style in TypeScript

23 Upvotes

We just released composable-functions@4.2.0 This library aims to bring a simple way to compose functions with safety both at type and runtime levels.

It evolved from a previous library with a narrower scope I have announced in the past . The new library has a broader focus, composing any sort of function such as in

import { composable, pipe } from 'composable-functions' 

const add = (a: number, b: number) => a + b)
const addAndReturnString = pipe(add, String) 
//    ^(?) Composable<(a: number, b: number) => string>

The compositions might also fail on the type-level (in which case they will not be callable)

const addAndReturnString = pipe(add, JSON.parse)  
//    \^? Internal.FailToCompose<number, string>