r/haskell • • 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.

17 Upvotes

29 comments sorted by

12

u/kindaro 10d ago

After a day of deliberation, I decided to voice my agreement with you.

  1. If you want a standard language model to generate plausible Haskell code, you need to load all kinds of examples and library documentation into the context, and let it reason for a good while. This would burn a lot of tokens and cost you a pretty penny. If you use techniques not familiar to the general population — recursion schemes, optics, fancy types, — you are in even more trouble. There are simply not enough examples of advanced stuff out there for the models to learn to imitate. I imagine if one were to compile a set of annotated examples to load as a system prompt it would improve the situation, but this would be tedious to undertake.
  2. Any code generated by a language model is incompatible with human work. This is true for any language but for Haskell it is true thrice. The verbosity of it will overwhelm you, the clumsiness of it will poison your mind. I grant that a well-posed problem that I can solve a bunch of agents running on the newest and largest language models will also solve, in a comparable amount of time. But their solution will be orders of magnitude longer and more complex. They will not learn from you and you better not learn from them.

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.

3

u/machinedgod 10d ago

Quite a rare feat nowadays, to sit on one's thoughts before stating them out! Kudos to you, sir.

> If you use techniques not familiar to the general population — recursion schemes, optics, fancy types, — you are in even more trouble

> Language models are great at searching through a code base. They are superhuman readers and associative thinkers

This was exactly my intuition about modern-gen models as well - but, the part that makes me feel gaslit, is that it seems that the sw engineering discipline as a whole greatly benefits from the usage of the assistants and agents to generate code from the quite loose specifications.
I can't figure out whether this is a statement about an LLMs capabilities or about the acceptable quality of sw engineering today - but in either case it seems to be a reliable signal that I've grown into a software engineer that's just too rigid for my own good.

While the advanced techniques are, I admit, fun to learn and use, the primary objective for me always was to write better, sturdier, faster and above all more readable codebase (readable as in "without ambiguities", not as in "as close to natural language"). This is why I transitioned to Haskell (from a quite rigidly defined and self-imposed subset of C++ features). If those traits aren't asked for any more - since codebase just gets regenerated from scratch - I suppose I've grown (with hindsight) in a wrong direction.

I am contemplating whether this transitionary period (marked by an unsettled gap between the hype and reality) simply requires going back to basics (languages and techniques) and employing the assistants in order to boost the output.

Weird times.

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:

  • You must give the LLM a way to build and run code. The feedback loop is critical. Imagine how bad you would be at programming if you were never allowed to compile or run anything!
  • I always start a session by asking for detailed plans before any implementation work, and sometimes need to remind the agent about this rule. If you let them just go off and start implementation blind, I often see weird design decisions that don't seem to happen as much (or get caught in time) when planning ahead.

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/

2

u/machinedgod 12d ago

Pretty good insights, thank you! I'll absolutely try this. As I replied to one other commenter, I haven't tried agentic IDE or anything like that just yet. It seems, from multiple replies, that this is where the main culprit is.

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.

3

u/machinedgod 12d ago

> It sounds like you're just using a chat interface to discuss problems with an LLM?

Correct, I should've specified this more directly - it seems this is the culprit!

Thank you for the advice, I haven't tried Claude yet or a proper assistant. This is a nudge in the right direction.

1

u/el_toro_2022 7d ago

I have done alot with Anthropic with both Haskell and C++. Using the chat interface, I upload tarballs to Claude, and then, at my prompting, will make the changes, and either give me patch files to change the local code, or generate tarballs to overwrite my project.

Of course, it goes without mention that I maintain and control changes using git, and Jujitsu makes that much easier to manage. Claude has also adopted to my workflow, so it will suggest the proper jj commands as well.

I know many would rather have it integrated into their IDEs, but really I see no need for that.

2

u/z3ndo 7d ago

Yeah I don't have any opinion on IDE integration as I don't use one. My point is mainly that the models will do better if they can iterate. I presume you're using a Claude Cowork session when you do what you described. For all intents and purposes that's not much different than a Claude Code session as far as feedback and iterating goes. If it can run a compiler itself against the code it suggested then it will do better than if it can't.

0

u/paulstelian97 12d ago

Even with agents those issues persist. I’ve seen at work.

1

u/z3ndo 12d ago

What issues? The one the op mentioned about not being able to produce usable software at all?

3

u/paulstelian97 12d ago

About making new code and fixing the wrong thing when the real fix tends to be sometimes just a single line or two. In my experience, most fixes to the problems I get handed over are a line or two that take a long time to find.

4

u/cartazio 11d ago

yeah, this happens way more than most folks realize. its pretty goofy, i'm working on my own harness tool chain that has definitely made this happen less while burning less reasoning on framework nonsese

→ More replies (1)

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.

1

u/machinedgod 12d ago

Thank you! I follow his writings and must've missed this entry. I've noticed Gabriella Gonzales also posted stuff, albeit her experience seems to be more in line with mine.

> 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.

Agreed. My own interest is very much in the area where I can lay down type signatures and have an LLM devise implementations. My guess is that with a bit of augmentation (ie. type reasoning) and well-laid-out signatures, it could produce quite optimal 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.

1

u/machinedgod 12d ago

Every bit of advice helps, thank you! I'll try Claude and will try using a proper agentic IDE.

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/machinedgod 7d ago

I would love to, but I am not sure what to search for 😅

I have installed Aider (coincidentally, precisely with pacman), so I'm going to spend the weekend exploring what it means to have a coworker that's constantly eager to please.

2

u/el_toro_2022 7d ago

1

u/machinedgod 5d ago

Hahaha, I mean I am sincerely thankful for the link but i meant specifically your AUR project :D

→ More replies (1)

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.

1

u/machinedgod 12d ago

Just generally available chat-interface models. I haven't engaged into paying for any advanced models because I was discouraged by initial attempts to get out something useful. Other posters suggested I try with agentic IDE, so I'll go down the Claude route and try it out.

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.