r/Python • u/enso_lang • Sep 19 '25
Showcase enso: A functional programming framework for Python
Hello all, I'm here to make my first post and 'release' of my functional programming framework, enso. Right before I made this post, I made the repository public. You can find it here.
What my project does
enso is a high-level functional framework that works over top of Python. It expands the existing Python syntax by adding a variety of features. It does so by altering the AST at runtime, expanding the functionality of a handful of built-in classes, and using a modified tokenizer which adds additional tokens for a preprocessing/translation step.
I'll go over a few of the basic features so that people can get a taste of what you can do with it.
- Automatically curried functions!
How about the function add, which looks like
def add(x:a, y:a) -> a:
return x + yUnlike normal Python, where you would need to call add with 2 arguments, you can call this add with only one argument, and then call it with the other argument later, like so:
f = add(2)
f(2)
42. A map operator
Since functions are automatically curried, this makes them really, really easy to use with map. Fortunately, enso has a map operator, much like Haskell.
f <$> [1,2,3]
[3, 4, 5]3. Predicate functions
Functions that return Bool work a little differently than normal functions. They are able to use the pipe operator to filter iterables:
even? | [1,2,3,4]
[2, 4]4. Function composition
There are a variety of ways that functions can be composed in enso, the most common one is your typical function composition.
h = add(2) @ mul(2)
h(3)
8Additionally, you can take the direct sum of 2 functions:
h = add + mul
h(1,2,3,4)
(3, 12)And these are just a few of the ways in which you can combine functions in enso.
5. Macros
enso has a variety of macro styles, allowing you to redefine the syntax on the file, adding new operators, regex based macros, or even complex syntax operations. For example, in the REPL, you can add a zip operator like so:
macro(op("-=-", zip))
[1,2,3] -=- [4,5,6]
[(1, 4), (2, 5), (3, 6)]This is just one style of macro that you can add, see the readme in the project for more.
6. Monads, more new operators, new methods on existing classes, tons of useful functions, automatically derived function 'variants', and loads of other features made to make writing code fun, ergonomic and aesthetic.
Above is just a small taster of the features I've added. The README file in the repo goes over a lot more.
Target Audience
What I'm hoping is that people will enjoy this. I've been working on it for awhile, and dogfooding my own work by writing several programs in it. My own smart-home software is written entirely in enso. I'm really happy to be able to share what is essentially a beta version of it, and would be super happy if people were interested in contributing, or even just using enso and filing bug reports. My long shot goal is that one day I will write a proper compiler for enso, and either self-host it as its own language, or run it on something like LLVM and avoid some of the performance issues from Python, as well as some of the sticky parts which have been a little harder to work with.
I will post this to r/functionalprogramming once I have obtained enough karma.
Happy coding.
23
u/enso_lang Sep 19 '25
Please feel free to ask any questions about enso here. I'd love to answer them. Or DM if you don't want to talk in public.
5
u/enso_lang Sep 19 '25
Apologies if anyone had a bunch of errors when the loaded up the REPL. It expects for their to be an rc file/history file/ and macro file present. I mean to make it so it would load empty versions of those files if it didn't find them but somehow it didn't get pushed.
18
u/me_myself_ai Sep 19 '25 edited Sep 19 '25
Really clean! As someone who makes liberal use of
functools, I’ll definitely be checking this out in the morning — just the ability to writefn = add(1)rather thanfn = ft.partial(add, 1)is already a HUGE selling point! A few random thoughts below, answer whatever subset you’d like :)fn = add(y=1)<$>, tbh.ovldanddspy), so I’m scared I’ll be hurt again lol.more-itertools? If not, they have some great ones to steal! Shoutout tounzip(),bucket(), andlocate()especially.Congrats on the big launch, regardless. Impressive stuff!
ETA: hell yeah, GitLab ✊✊✊
6
u/saint_geser Sep 19 '25
This sounds amazing! Couple questions:
5
u/Pythonistar Sep 19 '25 edited Sep 19 '25
This speaks to a very narrow Python audience. Vanishingly few people actually want ALL the features of Lisp in Python. (I say this having written my fair share of Lisp in the '90s)
My CS professor loved curried functions, but I could never find a great use for them in SWE. And it makes the code harder to read and debug, so I always avoided them.
Sigils always make code harder to read/understand. Reminds me of Perl. A write-once, read-never language.
I mean, this is great. For the writer of the macro, it definitely scratches an itch. But for anyone reading your code, now they need to understand and memorize your macros. (See: Sigils)
It's nifty what you've written, but I suspect you're going to have a tough time getting any serious uptake. Though I'm sure some folks will love it and really appreciate it.
Functional Programming (FP) has some great ideas (ie. lazy eval, function purity, first class functions, anonymous functions aka lambdas), but also some questionable ones, too.
I prefer to take the good and leave the bad. And I think Python has already done that very well!
Or put another way: The aspects in Lisp missing from Python are a feature, not a bug.
2
u/48panda Sep 20 '25
What happens if I do f(1) on
Does it immediately evaluate or do you have to specify to use the default for b?
3
u/TheRNGuy Sep 19 '25 edited Sep 19 '25
I wouldn't use that.
Some frameworks have matrix addition and multiplication. Those are methods for matric class (2d, 3d or 4d)
For basic floats and ints doing that is stupid. Writing
a + bis much easier (even for Matrix class there's operator overloading, so you can still domatrix1 * matrix2)1
u/jabellcu Sep 19 '25
I have read a bit about functional programming, but I don’t know much. Would you please go through the advantages of this framework? Is it about being more expressive and cleaner than regular python?
1
u/david-vujic Sep 19 '25
Wow, this looks nice! Like a functional language on top of Python, is there a “build” step or how does the Python runtime understand the syntax?
1
u/poopatroopa3 Sep 19 '25
Looks cool, but I was expecting comparisons to other packages... There's quite a few for Functional Programming in Python.
1
u/Gnaxe Sep 19 '25
How did you get the
f <$> [1,2,3]to parse? I was surprised it at least tokenized, butast.parse()doesn't work on it. This can't work by rewriting AST until you have AST.1
u/OneWhiteNight Sep 19 '25
Can you do pipes with this?
1
u/jI9ypep3r Sep 20 '25
This is really cool! Any reason why you didn’t just go with Haskell?
1
u/SprinklesFresh5693 Sep 20 '25
Why not use the same pipe operator as R for example? The |>
1
u/Fluid_Classroom1439 Sep 19 '25
This is fascinating, have you thought about proposing some of these things as PEPs?
2
u/Practical-Bike8119 Sep 21 '25
The name "Enso" is already used by another project related to functional programming: https://www.ensoanalytics.com/
1
u/Original-Ad-4606 Sep 19 '25
This looks awesome! I’ll check out your readme.
1
u/Few-Big7409 Sep 19 '25
Very cool. I got confused about the word direct sum. I think cartesian product, product, or direct product are better. In some categories the direct sum and product agree, but not all categories have direct sums. It is the case that many of the relevant categories do not have direct sums. In Set, for example, products and coproducts do not agree so there is no direct sum.
This is quite a minor point. I know the math language and am not familiar with the usage of direct sum in haskell or other things. So if your terminology generalizes common programming terminology I retract my comment.
Let me stress, I think this is quite cool. I am trying to figure out a way I can dive into it. Got your repo open now and going through the readme.
1
u/alkalisun Sep 19 '25
This is cool, I've explored some things like this but ultimately thought against using it because it would break compatibility with syntax checkers/LSPs. Essentially you're creating your own syntax which is really powerful. Nice stuff.
1
u/blankboy2022 Sep 21 '25
Isn't macro should be in a separated package? I mean by design that should be in a metaprogramming package or I'm perceiving anything wrong here?
1
u/Economy-Strawberry89 Sep 21 '25
Alguém do Brasil ai
1
u/Neither-Chemist-5055 Sep 21 '25
Why not just use coconut? For me it does what you want: https://coconut-lang.org/
1
u/[deleted] Sep 24 '25
This is really cool.
I don't know enough to fully understand what's going on here if I'm honest, but it's inspiring me to learn.
0
u/[deleted] Sep 22 '25
just downvoted this just because i dont find it useful