r/functionalprogramming • u/kinow • Nov 30 '22
r/functionalprogramming • u/jssmith42 • Feb 25 '22
Question Can you build all of mathematics in functional programming?
It seems like tools like Wolfram Mathematica try to turn math into a programming language.
But since math can be defined in terms of set theory, and functional programming is some kind of pure, mathematical form of programming,
is it possible or has anyone just written representations of mathematics objects - functions, algebraic structures, topology, etc - in functional programming purely, not within some secondary framework like Wolfram Mathematica?
Thank you very much.
r/functionalprogramming • u/luther9 • Nov 18 '21
OO and FP I'm learning monads by implementing IO in different languages
I'm doing this because there's not much talk about monads outside of Haskell (which I don't know much of), and I feel like I should be able to do FP regardless of language.
In Lua: The monad does its job of isolating side-effects, but then I have to write a lot of code to describe how those side-effects relate to each other. It seems that Haskell's syntactic sugar does almost all of the heavy lifting to manage side-effects in a readable way.
In Python: This uses a monad to echo the input. I found that the function stack keeps getting bigger as I input more lines. From that, I concluded that callable monads (ie, IO and State) are not feasible without proper tail calls.
In Scheme: I don't have any test code for this one. Unlike the other two, I did not go the OOP route with this. The "methods" simply operate on no-argument functions.
Hopefully, this might be interesting to some people. Let me know if there's any major concepts I missed.
r/functionalprogramming • u/kinow • Aug 22 '21
FP The Pyret Programming Language - an outstanding choice for programming education while exploring the confluence of scripting and functional programming
r/functionalprogramming • u/binaryfor • Aug 11 '21
Ξ» Calculus Kind - A modern proof language
r/functionalprogramming • u/amandiersenflrs • Dec 13 '20
Intro to FP Why FP Matters - Part 1Β½ π« - A bit of Haskell
r/functionalprogramming • u/paulshen • Sep 09 '20
TypeScript Monads for JavaScript/TypeScript developers
r/functionalprogramming • u/shiraeeshi • Jul 30 '20
Haskell How a Java Programmer Wrote Console Tetris In Haskell And What The Learning Curve Was Like
self.haskellr/functionalprogramming • u/Findlaech • Apr 30 '20
CompSci Opinions and feedback on βThe Optimal Implementation of Functional Programming Languagesβ
Hello everyone,
I was looking at the internet when I stumbled on this book, The Optimal Implementation of Functional Programming Languages.
Published in 1998/1999, more than ten years after Simon Peyton-Jones's own The Implementation of Functional Programming Languages, it is however way less referenced in the various book recommendations I have encountered on the Internet (I may thus have a bias here).
So, communities of /r/FunctionalProgramming and /r/ProgrammingLanguages, did even read this book, and if yes, what do you have to say about it? :)
r/functionalprogramming • u/MaoStevemao • Apr 27 '20
Haskell Blazing fast Fibonacci numbers using Monoids
haskellforall.comr/functionalprogramming • u/MaoStevemao • Mar 04 '20
Haskell Don't Fear the Profunctor Optics!
r/functionalprogramming • u/kinow • Feb 27 '20
FP Morel: A functional language for data
r/functionalprogramming • u/cntx • Dec 24 '19
Intro to FP A Glossary of Functional Programming
r/functionalprogramming • u/mrToppo • Nov 26 '19
Question Favorite FP language
Dear FP community of reddit,
What is your favorite FP language? Are you using it or any other fp language on production?
I really enjoy Eliixr and I'm able to use it on prod. I used to enjoy Scala, but now kinda hate it. Also fan of Haskell and `F#.
r/functionalprogramming • u/thefakewizard • Sep 28 '19
Haskell Learn Functional Programming by writing a Scheme in Haskell :: 0x0f0f0f
r/functionalprogramming • u/[deleted] • Sep 27 '19
Intro to FP A few days ago I started reading about functional programming and it's pretty cool
I'm a developer with 15 years of experience, but never worked with a functional programming language, my day to day languages in my career were:
PHP
Javascript :)
Actionscript
C#
Objective-c
Nodejs
Java
Swift
Kotlin
Ruby
C (just worked with it briefly)
Rust
Typescript
The list is long, there are some languages I don't use so often those days like Actionscript, PHP, Objective-c, C, Kotlin, Java, Swift, C#. But a while ago I started to work more on frontend web development (while previously I was doing purely backend development) and this gave me the oportunity to work a lot with React (I must say that I'm not impressed by any means with this framework, still prefer Vue over it), but all this gave me something to think about, and was that I don't like Javascript (it's like C, too easy to make mistakes and not to notice it, sure Typescript solve part of the problem, but still isn't as effective and like Elm author said, people don't like Java and Javascript with types is Java at the end of the day, too verbose, when you write you have a lot of code that is mostly boilerplate), so I started diggin in and said to me that I want to design a language that solve my problems (this is just my hobby project that I doit in my free time), then I read about this pure functional languages, they are indeed alien language (their syntax is not familiar to someone with my background), so Haskell, Ocaml, Lisp all were just too hard to read their syntax, then I meet Elm, and it's incredible how easy is to read and understand (yes for sure after learn Elm is easier to understand Haskell and Ocaml, Lisp is just too noisy for me with all the parenthesis (maybe haskell programmers feels the same for C like languages)).
So saying that I want to say, where and why functional programming isn't so popular, why Javascript is so bad while it could be easily beign a good functional language (it's what react recommends, but still it's a bit weird to do pure functional programming with Javascript).
Closing words, where has been pure functional languages all my life, I feel that I could have solved so many problems that I had this last couple of years.
PD: The post might feels uncoherent, and it's because I just wrote down what I was thinking as it comes out.
r/functionalprogramming • u/castleguar • Sep 25 '19
FP Discrete Math and Functional Programming (Textbook and Videos)
r/functionalprogramming • u/kinow • Mar 03 '19
OCaml Functional Programming in OCaml - Spring 2019 Edition
cs.cornell.edur/functionalprogramming • u/snappyTertle • Feb 23 '17
Functional Architecture
Any good resources on how to architect an app using FP techniques? I have a pretty good understanding of low level techniques, but want to learn how to tie them all together in real world scenarios.
r/functionalprogramming • u/kinow • Jul 27 '26
FP History of John Backus's FP languages
softwarepreservation.computerhistory.orgr/functionalprogramming • u/makingthematrix • Jun 04 '26
FP Scala Was an Experiment That Changed Programming - Martin Odersky | The Marco Show
r/functionalprogramming • u/EntryNo8040 • May 29 '26
Python Bringing rigorous Type Classes (Functor, Applicative, Monad) to Python: Introducing Katharos
If you come from Haskell or Rust and have to write Python for ML/AI work, you know the pain: if x is None everywhere, exceptions that silently swallow errors, no ? operator, no HKTs, no sealed types. I got tired of it and built a library to close that gap.
Katharos is a zero-dependency Python library that gives you Maybe, Either/Result, IO, the list monad, Semigroup, Monoid, Functor, Applicative, and Monad β all fully typed and passing pyright strict mode.
https://github.com/kamalfarahani/katharos
The Engineering Challenge
The hard part is that Python has no HKTs and no sealed keyword (as of 3.13). There's no way to say Functor f or write :: f a -> (a -> b) -> f b generically. The workaround is structural gymnastics: a two-parameter generic class hierarchy (Functor[F, A], Applicative[App, A], Monad[M, A]) plus @final on concrete types to prevent unsafe subclassing. It's not pretty internally, but the external API stays clean.
Operator Mapping
If you already think in Haskell or Rust, here's the translation table:
| Katharos | Haskell | Rust |
|---|---|---|
m | f | m >>= f | m.and_then(f) |
v ** wrapped_f | wrapped_f <*> v | β |
a >> b | a >> b | β |
a @ b | a <> b | β |
@do(M) decorator | do { ... } | β |
Examples
1. Maybe[A] β Haskell's Maybe a / Rust's Option<T>
No more if x is None chains. Short-circuits automatically on Nothing.
from katharos.types import Maybe
def safe_div(x: float) -> Maybe[float]:
return Maybe[float].Nothing() if x == 0 else Maybe[float].Just(10.0 / x)
def safe_sqrt(x: float) -> Maybe[float]:
return Maybe[float].Nothing() if x < 0 else Maybe[float].Just(x ** 0.5)
# | is >>=
Maybe[float].Just(4.0) | safe_div | safe_sqrt # Just(1.5811...)
Maybe[float].Just(0.0) | safe_div | safe_sqrt # Nothing() β short-circuits at safe_div
Maybe[float].Just(-1.0) | safe_div | safe_sqrt # Nothing() β short-circuits at safe_sqrt
# fmap for pure transformations
Maybe[int].Just(5).fmap(lambda x: x * 2) # Just(10)
Maybe[int].Nothing().fmap(lambda x: x * 2) # Nothing()2. Result[E, A] β Haskell's Either e a / Rust's Result<T, E>
Errors as values. The | chain (>>=) stops at the first Failure, exactly like Rust's ?.
from katharos.types import Result
def parse_int(s: str) -> Result[ValueError, int]:
try:
return Result[ValueError, int].Success(int(s))
except ValueError as e:
return Result[ValueError, int].Failure(e)
def validate_positive(n: int) -> Result[ValueError, int]:
if n > 0:
return Result[ValueError, int].Success(n)
else:
return Result[ValueError, int].Failure(ValueError(f"{n} is not positive"))
parse_int("42") | validate_positive # Success(42)
parse_int("abc") | validate_positive # Failure(ValueError("invalid literal..."))
parse_int("-5") | validate_positive # Failure(ValueError("-5 is not positive"))
# fmap only runs on the success path
parse_int("42").fmap(lambda n: n * 2) # Success(84)3. do-notation β Python do blocks, exactly like Haskell
The @do(M) decorator desugars yield into >>= chains. Each yield unwraps the value; short-circuits on Nothing/Failure. The final return is lifted via M.pure(...).
from katharos.syntax_sugar import do, DoBlock
from katharos.types import Maybe, Result
# Maybe β like Haskell:
# userScore uid = do
# name <- lookupUser uid
# score <- lookupScore name
# return (name ++ ": " ++ show score)
def lookup_user(uid: int) -> Maybe[str]:
db = {1: "alice", 2: "bob"}
return Maybe[str].Just(db[uid]) if uid in db else Maybe[str].Nothing()
def lookup_score(name: str) -> Maybe[int]:
scores = {"alice": 95, "bob": 87}
return Maybe[int].Just(scores[name]) if name in scores else Maybe[int].Nothing()
@do(Maybe)
def user_score(uid: int) -> DoBlock[str]:
name: str = yield lookup_user(uid)
score: int = yield lookup_score(name)
return f"{name}: {score}"
user_score(1) # Just(alice: 95)
user_score(99) # Nothing() β short-circuits at lookup_user
# Result β equivalent of Rust's ? in a pipeline
def parse_positive(x: int) -> Result[ValueError, int]:
return Result[ValueError, int].Success(x) if x > 0 else Result[ValueError, int].Failure(ValueError(f"{x} is not positive"))
@do(Result)
def compute() -> DoBlock[int]:
x: int = yield parse_positive(5)
y: int = yield parse_positive(3)
return x + y
compute() # Success(8)4. ImmutableList[T] β the list monad, non-determinism included
ImmutableList is a full Monad + Monoid. Bind (|) is concatMap. The do-notation gives you Haskell list comprehensions.
from katharos.types import ImmutableList
from katharos.syntax_sugar import do, DoBlock
# concatMap / flatMap
ImmutableList([1, 2, 3]) | (lambda x: ImmutableList([x, -x]))
# ImmutableList([1, -1, 2, -2, 3, -3])
# do-notation = list comprehension
# In Haskell: [(color, size) | color <- ["red","blue"], size <- ["S","M","L"]]
@do(ImmutableList)
def variants() -> DoBlock[tuple]:
color: str = yield ImmutableList(["red", "blue"])
size: str = yield ImmutableList(["S", "M", "L"])
return (color, size)
variants()
# ImmutableList([
# ('red','S'), ('red','M'), ('red','L'),
# ('blue','S'), ('blue','M'), ('blue','L')
# ])
# Monoid: @ is <>
ImmutableList([1, 2]) @ ImmutableList([3, 4]) # ImmutableList([1, 2, 3, 4])
ImmutableList.identity() # ImmutableList([]) β mempty5. Semigroup / Monoid β @ is <>
Sum, Product, and NonEmptyList are all Semigroup/Monoid instances. F.sigma is fold1 / sconcat over a NonEmptyList.
from katharos.types import NonEmptyList
from katharos.types.monoid import Sum, Product
from katharos.functools import F
# @ is <>
Sum[int](3) @ Sum[int](4) @ Sum[int](5) # Sum(12)
Product[int](2) @ Product[int](3) @ Product[int](4) # Product(24)
# identity() is mempty
Sum[int].identity() # Sum(0)
Product[int].identity() # Product(1)
# F.sigma is fold1 / sconcat β requires NonEmptyList (no empty-list footgun)
values = NonEmptyList(Sum[int](1), [Sum[int](2), Sum[int](3), Sum[int](4)])
F.sigma(values) # Sum(10)
# NonEmptyList itself is a Semigroup (no Monoid β no empty case)
nel1 = NonEmptyList(1, [2, 3])
nel2 = NonEmptyList(4, [5, 6])
nel1 @ nel2 # NonEmptyList([1, 2, 3, 4, 5, 6])Docs
Full docs at https://katharos.readthedocs.io. If this scratches an itch for you, a star on the repo goes a long way.