r/haskell • u/machinedgod • 12d ago
Your experience with LLM generated code (so I can sanity-check mine)
Hey all,
my first post here. Hope title clearly states its in good faith - I don't have solidified opinion, but the general public makes me feel gaslit so I am turning to you to help me realize where (and possibly if) am I wrong.
Context:
I have been software engineering for about 30 years now, and Haskell is my primary language for about 16. I'm reasonably confident with its edge features too - kinds, dependent types, type families and I've spent quite some time toying with linear types too.
The meat of the post:
so, I've attempted to use three different publicly available LLMs (CGPT, Grok and Gemini) to resolve a problem when I'd encounter that type of issue, where I am convinced my solution will work but puzzlingly, it doesn't. Those errors that depend on my misunderstanding of the problem - and consequentially the solution, not necessarily misunderstanding of my code.
My experience is universally such, that when asking an LLM to generate code for me - it would lead me down a wild goose chase. In about 15-20% of cases it would provide code that wouldn't even compile; in other cases, it requests changing type signatures - even when given all insight about types involved. In other cases it solves immediate problem at hand, but since I don't fully understand its code - and its explanation doesn't entirely encompass all the subtle edge cases - I end up with code that misbehaves only sometimes. Most of the time - it wants to modify entire codebase, foundational types, interactions between these types - and it wants to modify it in the way that practically nullifies the use of those types (such as requiring pattern matching of types that need to remain opaque).
I've observed this behaviour across multiple types of projects and even different languages; at one point I was trying to enroll its help to bind Rust ONNX library to a Haskell project, and it led me down two hours or wrong pathways. If I trusted my instinct in the beginning and doubled-down on it - it would've take me 10-15 minutes to find and fix the issue myself.
So far, the most useful workflow for me has been to forbid an LLM to generate any code - including pseudo code - and ask it to just analyze the problem and present me with a solution in form of a text so that I understand it better. This sometimes leads to a short conversation where I polish out questionable assumptions and then I have a working solution that is, more or less, 10-15 minutes to implement.
Some of my acquaintances and colleagues (not necessarily Haskell developers) said that they get the best results when they don't ask an LLM to solve only a small piece of a problem, but present it with the entire point of the project and let it develop everything and then iterate slowly over the wonky pieces, perhaps rewriting few by hand.
Not only that this is the opposite of my workflow, where I set up the architecture myself and try to employ LLM to solve small bits - it is also concerning to just run and keep a large body of code that I don't really understand. I don't do this with software written by humans either and will normally audit the developers, the company and/or the code itself.
After reading all this - would you care to share your experiences with 'vibe-coding' if you use it, and what kind of workflows work for you? I am getting increasingly concerned, over the past year, that I am "falling out" from technology because I don't know how to properly employ it, and I think this is affecting my ability to get work.
Thank you.
12
u/kindaro 10d ago
After a day of deliberation, I decided to voice my agreement with you.
Language models are great at searching through a code base. They are superhuman readers and associative thinkers. They can write passable technical documentation. They can easily reverse engineer obfuscated code. They have wide mathematical erudition. Long story short, they are great if you wish to inform yourself. But they are poor logical thinkers and therefore poor software engineers. Wield them for what they are good at.
16
u/matt-noonan 12d ago
I have had very good luck with Opus 5.5 writing complex Haskell code. I started using it after the project already had a fairly strict typing discipline and a well-designed architecture, and it has worked well within those constraints and understands the codebase thoroughly. Previous models were not as effective, and I would catch it doing things like claiming it ran and interacted with a GUI program when I could see that nothing of the sort had happened. Since Opus 5.5 I'm not getting any of this behavior anymore: it really does think up and run experiments to understand what is going on, builds and scripts interaction with the program, makes A/B tests, and generally does what I would expect of an actual software engineer.
A couple of important details:
Overall I have been pretty happy with the intersection of Haskell and LLMs; the benefits that Haskell brings to human developers also are benefits for agentic developers.
Here's the project, if you're curious. It's a cross-platform (Mac, Linux, Windows, web) GUI app for studying complex dynamics. It's currently about 50kloc of Haskell, 5kloc of TypeScript, and 1kloc of C: https://matt-noonan.github.io/FractalStream/
12
u/z3ndo 12d ago
It sounds like you're just using a chat interface to discuss problems with an LLM?
Most modern AI-based software development workflows use an agent so that it can iterate on a solution.
We're a Haskell shop that has adopted AI/agentic development workflows - mostly using Anthropic models - with quite a bit of success. The agent reads existing code, produces a plan, we discuss, then it implements while getting compiler, formatter, linting and test feedback. Then we code review locally, then a colleague reviews via PR. This has worked well for us but it results in reviewing a lot of code. The code isn't always perfect but it's much farther on the positive side than what you're describing.
With that said, while it's been a while since I've used a pure chat interface in anger to work on software I'm surprised your experience is so poor because the frontier models are all pretty good now.
Either way, you should try an actual coding assistant so it can get feedback on its work. Your codebases ability to provide automated feedback (i.e. tests, etc) will be important to maintaining consistency and code quality, but you will get a lot of mileage out of GHC alone.
EDIT: Since you mention experience - I will add that I have 25 years myself with the last 9 almost exclusively Haskell. At my company we've been doing AI/agentic development for about a year now.
5
u/trexd___ 12d ago
This post by Justin Le is a pretty good summary of my experience with Haskell and LLMs. I think we just need to to a better job at explaining what idiomatic Haskell is to LLMs since their training data on true idiomatic, high quality Haskell is most likely very low.
https://blog.jle.im/entry/llms-and-haskell-1-constraint-evading-behavior.html
Justin also has a series on idiomatic Haskell
https://blog.jle.im/entries/series/+five-point-haskell.html
I think at this point if you care about the quality of code when it comes to LLMs and Haskell you need to be extremely vigilant and work very closely with LLMs or else you'll essentially get pythonic code in Haskell rather than the Haskell code you're looking for. I say this as someone who is bullish on LLMs but I think as a community we need to do more to teach LLMs how to write good Haskell code.
2
u/mgomezch 12d ago
in general, up-front explicit specification is extremely important for these tools to follow your intent consistently. there are some workflows that tend to work better, e.g. https://drensin.medium.com/elephants-goldfish-and-the-new-golden-age-of-software-engineering-c33641a48874 it sounds like you've found a workflow along the same lines.
I haven't tried using LLMs for Haskell much, but I've gotten very impressive results in greenfield contexts where I don't specify the tools to use (or only lightly steer it away from tools I strongly dislike, and lightly steer in favor of tools I like, e.g. "don't use javascript anywhere" or "use nix for the build system"). for existing codebases, these tools require more hands-on attention/supervision than for greenfield projects.
LLM coding tool performance is heavily dependent on the model and harness. I've been impressed by Claude Code (Opus 5.5, and more so Fable 5.2), and mostly pleased by Gemini Argon/Carbon, and I've had much more mixed and often frustrating results from other harnesses/models. I would recommend giving Claude Code a try; it's not perfect but I'm much more often impressed than annoyed.
2
u/el_toro_2022 7d ago
I switched from Grok to Claude. Claude is amazing for Haskell. It's like having a super-junior dev at my every beck and call. Damned good for C++ as well, as I revived an old project and it's now on the AUR. Actually, my Haskell project is also on the AUR.
Claude. Check it out!
1
u/VincentPepper 12d ago
What models are you using where in 15-20% of cases the code doesn't even compile?
I won't sing opus generated code praises, but it very rarely generates broken code. And if it does it's usually something like a missing extension/import or similar that it will trivially fix in the next turn. And I tried Mistral/DeepSeek too and they are not much worse in that regard.
2
u/iamabubblebutt 12d ago
There is a huge gap between the current batch of free and paid models. I would only consider the best paid models from anthropic or openai to be usable for day-to-day work.
2
u/fluorihammastahna 12d ago
I have similar impressions. And honestly it feels like many are gaslighting themselves because as I user I don't see software getting shipped any faster.
1
u/jberryman 12d ago
Ya I would just switch to claude code and use it for a while and then see how you feel about it all. There's no real learning curve or configuration needed.
0
u/GunpowderGuy 12d ago
i use kimi to generate idris2 and haskell code. kimi k3.1 has never let me down. and k2.8 is a lot cheaper, but sometimes losses the plot
they do generate valid code with the constraints given
0
u/Mouse1949 12d ago
I used GPT and Claude to generate code (a bit of Gemini - not enough for an authoritative opinion). My experience - AI-generated code is pretty good, at least from the models released in the last 12 months or less. I still need to correct it occasionally - typically it understands what I told it to do too “creatively”. Still having it re-doing what’s wrong is faster than me doing it myself.