r/functionalprogramming • u/MagnusSedlacek • Mar 04 '25
FP Replace Your ORM With Relational Algebra by Christoffer Ekeroth
r/functionalprogramming • u/MagnusSedlacek • Mar 04 '25
r/functionalprogramming • u/kichiDsimp • Mar 03 '25
Hey fp-enjoyers.
I really want to do functional programming in a functional langauge. I learn fp from Haskell, arguably it was the most mind bending experience for me. But, when I tried building stuff with it (for example a TUI app) it was so tough, not enough community support along with not good documentation. (Please don't try to justify it)
I went on a ride with Clojure. I am skeptical about it. Shall I really spend my 6 months in it ? Or shall I just learn FP in JS/TS and implement stuff there and built it ? I have come across a book Grokking Simplicity. I don't know what's the depth and breath of it, but it seems readable . I have seen quite good GitHub repos with FP in JS. Turns out there is a SICP version also of JS.
Basically I want to build stuff, while writing beautiful, readable and enjoyable code. I have a image that Clojure is like this or maybe not ?
Please share your opinions !
r/functionalprogramming • u/kichiDsimp • Mar 01 '25
I spent a good dead of time with Haskell in 2024; I built JSON Parser . I want to try something new. Or maybe strengthen at Haskell ? But I really don't like the Haskell tooling...
I want to try dynamic fp language. I have Elixir or Clojure has options, for some reason I am inclined to Clojure.
To be a better programmer, I want to learn about Concurrent And Parallel Programming, I guess all the 3 languages are good place to learn
Suggest me something. Also some resources to get started.
I also came across a book Grokking Simplicity, I ready first few pages and surprisingly it was funny and easy to read but that book uses Javascript (it's dynamic but isn't really functional 😞)
r/functionalprogramming • u/quadaba • Feb 26 '25
At some point in the past I was reading about algebraic effects and how one could implement them using coroutines or continuation (eg in python); at another time I was reading that they were equivalent to monads. I was looking at the with block in Bend and decided to double check my understanding with you folks.
Is it true that all three (algebraic effects, monads, continuations) provide a way to add "custom logic" at every variable assignment or function call site - is that correct? Basically a way to add a custom wrapper logic around each call / override what it means to call a function? Kind of how we can override what operators or functions mean, but one abstraction level up - we are now overriding program control flow / "how function calls are applied and values are assigned"
Eg if we had a = f(b, c) wrapped in an effect handler or inside a monadic expression, that'd add extra custom logic before and after computing the value before assingment. All of the examples below could be implemented in python as we if all fn calls in a block were in the form a = yield (f, b, c) and the next caller implemented the corresponding logic (below), and some additional logic was applied when exiting the loop.
Some examples supporting this understanding:
Is that right?
r/functionalprogramming • u/ArturSkowronski • Feb 20 '25
r/functionalprogramming • u/MagnusSedlacek • Feb 19 '25
r/functionalprogramming • u/ClaudeRubinson • Feb 18 '25
Please join the Houston Functional Programming User Group on Wed, Feb 19 at 7pm central (2025-02-20 01:00 UTC) when Steven Proctor will present on using clojure.spec for parsing. clojure.spec is often used for validation and testing, but it can also be a useful tool for parsing data. This talk will provide a brief overview of clojure.spec, then show how it can be used to structure and extract information from data. We’ll look at practical examples and discuss when using clojure.spec as a parser makes sense.
Bio: Proctor is a high-functioning geek, that geeks out on programming languages, and functional programming. Proctor also hosts the podcast Functional Geekery.
HFPUG meetings are hybrid. If you're in the Houston area, you can join us in person at PROS. Otherwise, join us online via Zoom! For complete details, venue and connection info, please see our webpage at https://hfpug.org.
r/functionalprogramming • u/jmhimara • Feb 16 '25
By "tool" I mean both the language and framework/library combination that enable you to create GUIs in a "functional" way (more or less). I found that many FP languages don't necessarily have great GUI libraries -- they're usually thin wrappers over some other library (e.g. GTK or electron). At least the ones I've tried.
Racket has a pretty decent GUI library, and while I enjoy writing lisp for short programs, it's not my favorite for big projects. F# is supposed to have a couple of decent GUI libraries but their not fully cross-platform -- well, Avalonia is supposed to be but I couldn't get it working on linux last time I tried. And the docs for the F# bindings seem incomplete.
I guess there is typescript+react+electron, if you consider that functional.
What technology have you used for your GUI programs that you've found enjoyable and relatively mature?
r/functionalprogramming • u/kinow • Feb 15 '25
r/functionalprogramming • u/crowdhailer • Feb 14 '25
r/functionalprogramming • u/Frere_de_la_Quote • Feb 14 '25
Pattern matching and logical programming represent two fundamental paradigms in computer science. LispE elegantly shows how logical programming can be viewed as a generalization of pattern matching through its defpat and defpred mechanisms.
(see LispE for more information)
Pattern matching in LispE starts with defpat, which provides a sophisticated system for function polymorphism. With defpat, you can define multiple versions of the same function that differ in their parameter patterns:
; Different patterns for the same function name
The key aspects of defpat are:
(see defpat documentation)
defpred builds upon this foundation by transforming pattern matching into a logical programming framework. The crucial evolution lies in how function bodies are handled:
; Pattern matching version
; Regular evaluation
; Logical programming version
; Must return true/false
Here are the key transformations that defpred introduces:
Boolean Transformation:
Failure Handling:
; These lines never execute
Implicit Cut:
Here's a more complex example showing this behavior:
; Base case for empty list
; Process rest of list
; Only reached on failure
; When called with: (process-list '(1 2 11 12))
; Output:
; 1
; 2
; Alternative path: (11 12)
This example demonstrates how:
What makes defpred particularly interesting is how it bridges pattern matching and logical programming:
Pattern Matching Foundation:
defpat's pattern matching capabilitiesLogical Programming Extension:
Hybrid Approach:
; Action (must return true)
This hybrid approach allows LispE to:
This evolution from pattern matching to logical programming has practical benefits:
Clearer Error Handling:
Controlled Backtracking:
Deterministic Behavior:
LispE's evolution from defpat to defpred demonstrates how logical programming can be seen as a natural extension of pattern matching. By transforming function bodies into boolean predicates and adding controlled backtracking, LispE creates a powerful hybrid that maintains the benefits of both paradigms while adding its own unique characteristics through implicit cuts.
This approach shows that the gap between pattern matching and logical programming isn't as wide as it might appear, and that combining their strengths can lead to elegant and practical programming solutions.
r/functionalprogramming • u/oakleycomputing • Feb 13 '25
I have been working on a compiled functional language and have been trying to settle on ergonomic syntax for the grad operation that performs automatic differentiation. Below is a basic function in the language:
square : fp32 -> fp32
square num = num ^ 2 Is it better to have the syntax
grad square <INPUT>evaluate to the gradient from squaring <INPUT>, or the syntax
grad squareevaluate to a new function of type (fp32) -> fp32 (function type notation similar to Rust), where the returned value is the gradient for its input in the square function?
r/functionalprogramming • u/lovelacedeconstruct • Feb 11 '25
I dont write java anymore but my experience with Java back in college was that it was very good introduction to OOP, everything was a class, syntax was very close to the diagrams, it felt like the concepts of OOP was just all there and you are forced to think using them, not saying whether thats a good thing or not or whether my assessment was correct but what do you think is the equivalent for FP ?
r/functionalprogramming • u/Frere_de_la_Quote • Feb 10 '25
I have implemented a LispE interpreter that offer some high level functions such as map or filter. However, these functions are treated as macros and can be easily composed one with the others.
It is actually quite simple to see the result of this composition, which might help you understand some concepts such as lazy evaluation.
; is actually transformed into one single loop,
; which takes the following form:
Hence, when a sequence of calls to these methods is made, the system automatically factorizes them into one single loop.
If you want to know how your different functions have been composed, the easiest way is to store them in a function and to display the content of that function.
; Displaying the content of 'tst'
Applies action to each element from list and yields a list out of the results.
; (1 4 9 16)
Applies an operation to each item in a list
returns
returns
; important, we interpret (1 -) as (- x 1)
returns
; Important, we interpret (- 1) as (- 1 x)
returns
returns
;An amusing example, we execute a shell command
!v=ls
; But 'v' contains strings ending in carriage return.
; This is how you can initialize all the strings at once.
Filters the items in a list. The condition can be a lambda.
returns
returns
Drops nb elements from a list and returns the remainder.
Skips all items meeting the condition, then returns the rest.
returns
Take nb elements from a list.
Create a list, in which value is repeated nb times.
; yields ((1 2) (1 2) (1 2) (1 2))
Create a list, in which value is stored over and over again. It should be associated with a take for instance.
; yields: (5 5 5 5 5 5 5 5 5 5)
Create a list, in which we cycle through liste to store in. It should be associated with a take for instance.
Keeps all the elements satisfying the condition and then removes the rest.
) ; returns (1 3 5 9)
Infinite range, starting at initial by increment step.
; yields: (1 3 5 7 9)
; yields: (1 9 25 49 81)
This specific irange is used to avoid creating a list of integers beforehand in a loop with range. It implements an increment-based loop.
This specific irangein is used to avoid creating a list of integers beforehand in a loop with range. It implements an increment-based loop. The difference with irange is that the bound is part of the values.
;0
;1
;2
;3
;4
;5
applies an operation on a list, providing an initial value from the beginning of the list
; gives 4
Same as foldl but takes the first item in the list as first value
; gives -4
as foldl but starts from the end of the list
as foldl1 but starts from the end of the list
Keeps the list of intermediate items in a list
; gives (10 -10 -40 -80)
Same thing, but we use the first element of the list for the calculation.
; gives (20 -10 -50)
We start from the end of the list for the accumulation
; gives (11 8 3 1 0)
We start from the end of the list for the accumulation and use the last item for the operations
Allows to make a list from the list elements given as arguments.
; gives ((1 4 7) (2 5 8) (3 6 9))
Allows to apply an operator between list items.
; yields (12 15 18)
zipwith creates a list based on the type of the first element that is returned by the lambda or the operation. For instance, in the above example, zipwith will return a list of integers: integers.
zipwith can take a last parameter, which can be true or false to force the output to be a regular list:
; yields integers_
; yields list_
The non composition operator: !prevents LispE from combining two structures:
; We let LispE compose the following expression.
; At each step it processes both the scanl1 and the map
; result is (10 900 864900)
; We prevent LispE from composing in the following expression:
; result is (100 900 3600)
There are two different sorts of scan/fold functions:
l at the end of the function name)r at the end of the function name)These two sorts of function not only process lists in a reverse order, they also compute their values in a reverse order.
Compare for instance:
; yields -4
; yields 2
If you use a lambda function then this lambda must take two arguments, but the order of the arguments depends on the type of functions.
; left function, the accumulator is the first argument
; right function, the accumulator is the second argument
r/functionalprogramming • u/MagnusSedlacek • Feb 10 '25
r/functionalprogramming • u/Active-Fuel-49 • Feb 09 '25
r/functionalprogramming • u/mttd • Feb 08 '25
r/functionalprogramming • u/fenugurod • Feb 04 '25
I'm learning pure FP in Scala right now, and it works really well, but the reasoning is based on discipline given that at any given point effects can be generated at any part of the code. So the whole idea of reasoning falls apart because at any import, specially coming from Java, this property can be violated.
r/functionalprogramming • u/faiface • Feb 01 '25
Hey everyone!
I've been fascinated with linear logic, session types, and the concurrent semantics they provide for programming. Over time, I refined some ideas on how a programming language making full use of these could look like, and I think it's time I share it!
Here's a repo with full documentation: https://github.com/faiface/par-lang
Brace yourself, because it doesn't seem unreasonable to consider this a different programming paradigm. It will probably take a little bit of playing with it to fully understand it, but I can promise that once it makes sense, it's quite beautiful, and operationally powerful.
To make it easy to play with, the language offers an interactive playground that supports interacting with everything the language offers. Clicking on buttons to concurrently construct inputs and observing outputs pop up is the jam.
Let me know what you think!
define tree_of_colors =
.node
(.node
(.empty!)
(.red!)
(.empty!)!)
(.green!)
(.node
(.node
(.empty!)
(.yellow!)
(.empty!)!)
(.blue!)
(.empty!)!)!
define flatten = [tree] chan yield {
let yield = tree begin {
empty? => yield
node[left][value][right]? => do {
let yield = left loop
yield.item(value)
} in right loop
}
yield.empty!
}
define flattened = flatten(tree_of_colors)
Par (⅋) is an experimental concurrent programming language. It's an attempt to bring the expressive power of linear logic into practice.
Despite the language being dynamically typed at the moment, the above properties hold. With the exception of no unreachable processes, they also hold statically. A type system with linear types is on the horizon, but I want to fully figure out the semantics first.
All values in Par are channels. Processes are intangible, they only exist by executing, and operating on tangible objects: channels. How can it possibly all be channels?
Some features important for a real-world language are still missing:
One non-essential feature that I really hope will make it into the language later is reactive values. It's those that update automatically based on their dependencies changing.
Par is a direct implementation of linear logic. Every operation corresponds to a proof-rule in its sequent calculus formulation. A future type system will have direct correspondence with propositions in linear logic.
The language builds on a process language called CP from Phil Wadler's beautiful paper "Propositions as Sessions".
While Phil didn't intend CP to be a foundation of any practical programming language (instead putting his hopes on GV, a functional language in the same paper), I saw a big potential there.
My contribution is reworking the syntax to be expression-friendly, making it more visually paletable, and adding the whole expression syntax that makes it into a practical language.
r/functionalprogramming • u/ivanimus • Feb 01 '25
Hi there!
I'm currently working as a Data Engineer and I'm interested in learning a functional programming language for personal growth and side projects. While I'm aware that job opportunities in pure functional programming are limited, I'm passionate about expanding my programming paradigm knowledge.
What would you recommend for someone in my position? I'm particularly interested in hearing about:
Thank you in advance for your suggestions!
r/functionalprogramming • u/bikethiefgobrrrrr • Jan 28 '25
Hi, I don't know where to ask. I'm looking for an excellent talk I saw on YouTube, whose title has escaped my memory. It was an introduction on how to have side effects in functional languages, from monads to free to algebraic effects. The theme of the talk was very medieval, and it was set in a fictional land where each programming language was its own kingdom, where the evil "side effects" lived. It was very story-telly though still featured some ADTs. I think it was around 20-30 minutes long, and held at some in-person convention (though I do not remember which year either). Does anyone know which one I am looking for?
EDIT: Found it, "Lambda World 2019 - A Series of Unfortunate Effects - Robert M. Avram" link