Abhinav Sarkar
abhin4v.bsky.social
Abhinav Sarkar
@abhin4v.bsky.social
Programming languages aficionado, occasional runner, quantified-self enthusiast, and fervent napper. Works as senior software engineer at Google. Also at @abnv.me.

#programminglanguages #software #running #Haskell #NixOS #photography #quantifiedself
Pinned
Do you want to learn how to create beautiful and useful #REPL for your #ProgrammingLanguages written in #Haskell? I wrote a Haskeline tutorial just for you: abhinavsarkar.net/posts/replin...
#blog #programming
Going REPLing with Haskeline
We use Haskeline to create a REPL for our new programming language.
abhinavsarkar.net
Reposted by Abhinav Sarkar
The new #weeknote is out with news about health, books read and projects done: https://abhinavsarkar.net/notes/2025-weeknotes-11-23/

#blogging
Notes for the Week #47
This week note covers the week of 17th–23rd October. Halfpipe * Starting with health, this week was again fraught with infections. They say toddlers are walking Petri dishes, and it’s not far from truth. My wife and I had a minor viral infection this week but thankfully the toddler was fine. Still, I didn’t feel at 100% and could not get a lot done. * I finished reading _This is How You Lose the Time War_! This is the first fiction book that I’ve read since 2021. Early parenthood is difficult, and sadly, reading fiction was the first thing I gave up. I tried, but it just didn’t hold my (scattered) attention. Thankfully, it’s coming back to me. The book itself was a fascinating read. I’m not much into romances but this one was very different. I’m yet to take the full feeling in, and I will certainly go back and reread parts of it. I wholly recommend it if you are into reading sci-fi and/or romance. * This week, I finally had time and motivation to work on a side project that I’ve been trying to do for months. I wanted a service that takes an RSS feed, and sends me 10 (or 3) items from it every day using a space repetition algorithm as another feed. That way, I can provide it a feed of my favourite articles that I want to keep coming back to, and get to read them again and again over years. After mulling over this for six months and doing two overly complex prototypes, I finally came up with something that works well enough and fits under 500 lines of code. Six months to think, one day to write! I had to let go of using a spaced repetition algorithm because that requires statefulness, and I wanted a stateless minimal solution. So instead the program selects entries randomly with exponential weights calculated from age of entries using the A-Res algorithm. This biases selection toward older entries, making them more likely to be repeated. The repeated entries have their timestamp updated, and become less likely to be repeated again in the near future. I call this program _feed-repeat_ and it is running on my VPS now, echoing my Linkblog and Blogroll feeds. * Some interesting links for this week: * Towards interplanetary QUIC traffic * Why Lexing and Parsing Should Be Separate * Why you speak more Latin than you think That’s all for this week. You can subscribe to the feed of my week notes for updates. If you have any questions or comments, please leave a comment below. If you liked this post, please share it. Thanks for reading!
abhinavsarkar.net
November 23, 2025 at 8:42 AM
Reposted by Abhinav Sarkar
still kind of wild that unwrap is a thing in rust.

like, rust people will be so smug about how their language doesn't have null pointers and then add a function that replicates nullpointerexceptions right in their standard library?
June 15, 2025 at 10:35 AM
Reposted by Abhinav Sarkar
I can't get over the fact that #rust invented `Option` to avoid NULL pointers, and then added `unwrap` to it, undoing the whole thing.
November 19, 2025 at 5:00 AM
Reposted by Abhinav Sarkar
November 15, 2025 at 5:29 AM
Reposted by Abhinav Sarkar
Gave my aging #mechanicalkeyboard a makeover by changing keycaps. The mix of colors looks pretty cool.
November 15, 2025 at 7:14 AM
Reposted by Abhinav Sarkar
Change of Mind
_I wrote this post for a prompt given during ourlocal Indieweb club meeting: “What did you recently change your mind about?”_ I’ve always wanted to write a book, some book, since I can remember, for reasons I’ll not go into in this post. Initially, I had no clue what I wanted to write about. Over years (decades really), I slowly zeroed it down to writing a book about compilers in Haskell. I got interested in Functional Programming while I was a wee J2EE developer back in the aughts. The first language that caught my fascination was Clojure, the excellent Lisp on JVM. But soon enough, the dark side of static typing seduced me and I fell in love with Haskell. Over a decade or so, I’ve read and written enough Haskell code that I can call myself proficient in it. Haskell is now the first language that I reach out to, no matter the size of my project, which I believe is something very uncommon. Along with Haskell and functional programming, usually comes the allurement of compilers and creating your own programming languages. And sure enough the bug bit me hard when the world stopped in 2020. I spent countless hours learning all things compilers from scratch, and writing many of them in Haskell. An idea crossed my mind one day, why not write a book on compilers using Haskell? I spent some time digging up. Turns out, there is only one compiler book that uses Haskell as its implementation language. This is a very bizarre and curious fact, because one of the biggest strengths of Haskell is writing compilers, and there are tens if not hundred of them written already. But only one person wrote a book about the process! I decided to snatch this opportunity. Thereafter, I spent a lot of time thinking about the book, more than a year actually. I wrote the table of contents, I thought about how I’d structure the code examples, even about the publishing software. I also read multiple articles about the process of book-writing by people who have successfully published. After a lot of deliberation and talking to friends, I’ve changed my mind about writing _the_ book. The effort to result ratio just does not seem worth it. This is more true for the kind of writing I do / want to do—an in-depth everything-explained all-code-provided book. I know that I would not be satisfied with anything less. I suspect that if I go down this path, it would take a good chunk of my forties, and I’ll not have enough to show for all the time I put in it. Of course, I could be wrong, but this is what I feel right now. So, I’m changing my mind and I’m giving up. So long, my childhood dream of becoming a famous published author. But it’s not all sad and gloom. I’ll probably do something more useful and fun with my time. I really think that I’ll not regret this decision. But if I do, I suppose I can change my mind about it again! If you have any questions or comments, please leave a comment below. If you liked this post, please share it. Thanks for reading!
abhinavsarkar.net
November 15, 2025 at 1:23 PM
Reposted by Abhinav Sarkar
Kyle Kingsbury is not a journalist. He is not an op-ed writer.

He is a computer safety researcher.

And he has written one of the most compelling, comprehensive accounts of the ongoing hell in Chicago that you could possibly imagine.

In under 1600 words.

aphyr.com/posts/397-i-...
November 9, 2025 at 8:49 PM
Reposted by Abhinav Sarkar
A Short Survey of Compiler Backends
As an amateur compiler developer, one of the decisions I struggle with is deciding choosing the compiler backends. Unlike the 80’s when people had to target various machine architectures directly, now there are many mature options available. This is a short and very incomplete survey of some of the popular and interesting options. ### Contents 1. Machine Code / Assembly 2. Intermediate Representations 3. Other High-level Languages 4. Virtual Machines / Bytecode 5. WebAssembly 6. Meta-tracing Frameworks 7. Unconventional Backends 8. Conclusion ## Machine Code / Assembly A compiler can always directly output machine code or assembly targeted for one or more architectures. A well-known example is the Tiny C Compiler. It’s known for its speed and small size, and it can compile and run C code on the fly. Another such example is Turbo Pascal. You could do this with your compiler too, but you’ll have to figure out the intricacies of the _Instruction set_ of each architecture (ISA) you want to target, as well as, concepts like register allocation. ## Intermediate Representations Most modern compilers actually don’t emit machine code or assembly directly. They lower the source code down to a language-agnostic _Intermediate representation_ (IR) first, and then generate machine code for major architectures (x86-64, ARM64, etc.) from it. The most prominent tool in this space is LLVM. It’s a large, open-source compiler-as-a-library. Compilers for many languages such as Rust, Swift, C/C++ (via Clang), and Julia use LLVM as an IR to emit machine code. An alternative is the GNU C compiler (GCC), via its GIMPLE IR, though no compilers seem to use it directly. GCC can be used as a library to compile code, much like LLVM, via libgccjit. It is used in Emacs to _Just-in-time_ (JIT) compile Elisp. Cranelift is another new option in this space, though it supports only few ISAs. For those who find LLVM or GCC too large or slow to compile, minimalist alternatives exist. QBE is a small backend focused on simplicity, targeting “70% of the performance in 10% of the code”. It’s used by the language Hare that prioritizes fast compile times. Another option is libFIRM, which uses a graph-based SSA representation instead of a linear IR. ## Other High-level Languages Sometimes you are okay with letting other compilers/runtimes take care of the heavy lifting. You can transpile your code to a another established high-level language and leverage that language’s existing compiler/runtime and toolchain. A common target in such cases is C. Since C compilers exist for nearly all platforms, generating C code makes your language highly portable. This is the strategy used by Chicken Scheme and Vala. Or you could compile to C++ instead, like Jank, if that’s your thing. Another ubiquitous target is JavaScript (JS), which is one of the two options (other being WebAssembly) for running code natively in a web browser or one of the JS runtimes (Node, Deno, Bun). Multiple languages such as TypeScript, PureScript, Reason, ClojureScript, Dart and Elm transpile to JS. Nim interestingly, can transpile to C, C++ or JS. A more niche approach is to target a Lisp dialect. Compiling to Chez Scheme, for example, allows you to leverage its macro system, runtime, and compiler. The Idris 2 and Racket use Chez Scheme as their primary backends. ## Virtual Machines / Bytecode This is a common choice for application languages. You compile to a portable bytecode for a _Virtual machine_ (VM). VMs generally come with features like _Garbage collection_ , _JIT compilation_ , and security sandboxing. The Java Virtual Machine (JVM) is probably the most popular one. It’s the target for many languages including Java, Kotlin, Scala, Groovy, and Clojure. Its main competitor is the Common Language Runtime, originally developed by Microsoft, which is targeted by languages such as C#, F#, and Visual Basic.NET. Another notable VM is the BEAM, originally built for Erlang. The BEAM VM isn’t built for raw computation speed but for high concurrency, fault tolerance, and reliability. Recently, new languages such as Elixir and Gleam have been created to target it. Finally, this category also includes MoarVM—the spiritual successor to the Parrot VM—built for the Raku (formerly Perl 6) language, and the LuaJIT VM for Lua, and other languages that transpile to Lua, such as MoonScript and Fennel. ## WebAssembly WebAssembly (Wasm) is a relatively new target. It’s a portable binary instruction format focused on security and efficiency. Wasm is supported by all major browsers, but not limited to them. The _WebAssembly System Interface_ (WASI) standard provides APIs for running Wasm in non-browser and non-JS environments. Wasm is now targeted by many languages such as Rust, C/C++, Go, Kotlin, Scala, Zig, and Haskell. ## Meta-tracing Frameworks _Meta-tracing Frameworks_ are a more complex category. These are not the backend you target in your compiler, instead, you use them to build a custom JIT compiler for your language by specifying an interpreter for it. The most well-known example is PyPy, an implementation of Python, created using the RPython framework. Another such framework is GraalVM/Truffle, a polyglot VM and meta-tracing framework from Oracle. Its main feature is zero-cost interoperability: code from GraalJS, TruffleRuby, and GraalPy can all run on the same VM, and can call each other directly. ## Unconventional Backends Move past the mainstream, and you’ll discover a world of unconventional and esoteric compiler backends. Developers pick them for academic curiosity, artistic expression, or to test the boundaries of viable compilation targets. * Brainfuck: An esoteric language with only eight commands, Brainfuck is _Turing-complete_ and has been a target for compilers as a challenge. People have written compilers for C, Haskell and Lambda calculus. * Lambda calculus: Lambda calculus is a minimal programming languages that expresses computation solely as functions and their applications. It is often used as the target of educational compilers because of its simplicity, and its link to the fundamental nature of computation. Hell, a subset of Haskell, compiles to Simply typed lambda calculus. * SKI combinators: The SKI combinator calculus is even more minimal than lambda calculus. All programs in SKI calculus can be composed of only three combinators: S, K and I. MicroHs compiles a subset of Haskell to SKI calculus. * JSFuck: Did you know that you can write all possible JavaScript programs using only six characters `[]()!+`? Well, now you know. * Postscript: Postscript is also a Turing-complete programming language. Your next compiler could target it! * Regular Expressions? Lego? Cellular automata? ## Conclusion I’m going to write a compiler from C++ to JSFuck. If you have any questions or comments, please leave a comment below. If you liked this post, please share it. Thanks for reading!
abhinavsarkar.net
November 5, 2025 at 11:17 AM
Reposted by Abhinav Sarkar
November 3, 2025 at 5:58 PM
Reposted by Abhinav Sarkar
Notes for the Week #43
This week note covers the week of 20th-26th Oct. The Loovre * The week started with Diwali. We made a rangoli, lit lamps and decorated with lights. We had great food for breakfast and lunch. The sky was filled with fireworks. It was a lot of fun, especially for my little one. * I wrote a new blog post, concluding my “A Fast Bytecode VM for Arithmetic” series. Some friends have asked me how long it takes me to write these posts, so this time I paid attention. The idea came to me on 28th January 2025, and the series ended on 21st October 2025. So it took me about nine months from conception to end. I did about 70 revisions (commits) of the code, and about 50 revisions of the post text over the months. The end result was over 8300 words of text and 1700 lines of code. * I finally got the count of unread items in my feed reader below 1000. For a while, it peaked around 1800! * The traffic has been a dream this week. The stretch that took me three hours last week, took only 30 minutes this time. This amount of variation is crazy, to be honest. * I’ve been diving deeper into Jujutsu, and now I’m quite comfortable with it. I don’t use most of its advanced features on my personal repos, but I still feel like it is much easier than Git. * I finished watching _City the Animation_ , and I absolutely loved it. It’s wonderful to see a wacky anime about nothing after a long period of remakes and rehashes. I greatly enjoyed the finale that unexpectedly turned into a musical. * Though my health has been improving consistently, this week I faced debilitating shoulder pain caused by my bad posture. I must constantly remind myself that I’m too old to work for hours in bad postures. Thankfully, the hot water bag and slow stretching helped, and now I’m feeling better again. * On to regular website updates: * Some friends gave me harsh feedback on the bad readability of the justified text of posts, so it is back to being left aligned. * I added popular posts and notes pages. * We visited some old friends this weekend and it was lovely to catch up after a long gap. We chatted for hours about all things in the world, including good breads, modern cars, investing for future, writing books, making personal software, and setting up routers. They gifted me some keycaps and now my old keyboard looks amazing again. That’s all for this week. Write to me in the comments. If you have any questions or comments, please leave a comment below. If you liked this post, please share it. Thanks for reading!
abhinavsarkar.net
October 26, 2025 at 4:01 PM
Reposted by Abhinav Sarkar
I've written a series of blog posts, in which I write a #bytecode #compiler and a #virtualmachine for arithmetic in #haskell. We explore the following topics in the series:

- Parsing arithmetic expressions to ASTs.
- Compiling ASTs to bytecode.
- Interpreting ASTs.
- Efficiently executing […]
Original post on fantastic.earth
fantastic.earth
October 21, 2025 at 3:14 PM
Reposted by Abhinav Sarkar
Don't get too hung up on #Monads, there are other ways to sequence effects; including Arrows; and they provide even better static analysis!

Let me know what you think :)

#Haskell

chrispenner.ca/posts/arrow-...
Exploring Arrows for sequencing effects
Monads are <em>one</em> way to sequence effects, but they're not the only way!
chrispenner.ca
October 21, 2025 at 2:41 AM
Reposted by Abhinav Sarkar
The website of #indieweb Club #bangalore is finally up at https://blr.indiewebclub.org
IndieWebClub Bangalore
Website of the IndieWebClub Bangalore community
blr.indiewebclub.org
October 19, 2025 at 6:17 AM
Reposted by Abhinav Sarkar
Notes for the Week #42
This week note covers the week of 13th-19th Oct. A Desert Orchard * Bangalore—the city I live in—is notorious for its bad traffic. I had a confirmation of it just this week, when I was stuck in a cab for **three entire hours**. The traffic jam made the news, like many such before it, but experiencing it first-hand was a crazy thing. As I sat there in the cab for three whole hours, hungry, thirsty, sleepy but unable to sleep, I became so distraught that it made me challenge my belief that Bangalore is a good city to live in. Something will have to change. * As they say, you are not stuck in traffic, you are traffic. So better learn how to drive in Bangalore by reading this great guide by my friend Kiran. I’ve been thinking of writing such a piece for years now, but Kiran did it better than I could ever do, so now I don’t have to do it anymore. * I can’t write about my work in details, but I can tell you that I hate shift-reduce conflicts now. * On health, I’m feeling better with every passing day. Strength, clarity and curiosity is returning to me in waves. * Ankur convinced me to try Jujutsu (JJ), the new VCS that everyone is talking about these days. I configured it on my website’s repo, and it somehow deleted all the untracked files! After struggling for a bit, I fixed the repo by running multiple arcane Git commands (`reset/restore`, `for-each-ref`, `update-ref`). My strong suggestion is to deal with all the untracked files before you try JJ, by committing them to branches, or stashes, or adding them to `.gitignore`. JJ has no staging area unlike Git, and commits everything automatically. It also makes it easy to rewrite history, leading to lost commits. Together, they are a great recipe for losing untracked files. I’m starting to get a hang of JJ now after using it for few days. I’ve been working with Mercurial for the last six years at Google, so picking up JJ was quite easy for me, as JJ borrows a lot of concepts from Mercurial. The hardest part was abandoning the Git mindset of branches and rebases. * One Punch Man Season 3 is out! I’ve been waiting for it for six years! I can’t believe it took such a long break, but then the last six years have been pretty terrible for the world so I can understand. * I attended another fun IndieWebClub Bangalore meeting on Saturday. This was a technical session and we had a lively discussion about: * The right domain name for the IndieWebClub Bangalore website. * Adding share buttons to websites. * Pros and cons of adding Open Graph tags to websites. * Rendering charts on server-side for blog posts. * Justifying text on internet. * Automation. We finally **launched** the IndieWebClub Bangalore website at blr.indiewebclub.org! I also wrote a note for the writing exercise. * Moving on to personal projects, I did some more polishing of this website this week: * I added Atom feeds for the Readings and Activities pages. * I added my latest photo to the homepage. * I fixed some styling to switch from using tables to CSS. * Perceptive readers may have noticed that the text in the posts and notes is aligned justified now. Let me know how you feel about it. * Some interesting things I read on the internet this week: * Modeling State Machines with Dependent Types in Haskell * How Rhyme Works (and Why) * All I want for Christmas is a negative leap second That’s all for this week. Catch up with me in comments. If you have any questions or comments, please leave a comment below. If you liked this post, please share it. Thanks for reading!
abhinavsarkar.net
October 19, 2025 at 7:13 AM
Reposted by Abhinav Sarkar
Wrote some JavaScript code to customize #miniflux #feedreader to automatically sort articles by similarity. Now I can read similar articles one after another easily.
September 28, 2025 at 1:05 PM
Reposted by Abhinav Sarkar
New blog post!

#Haskell is built on a foundation of Monads, but are they really the optimal way to sequence effects or should we keep looking for something better?

What's the big deal with Applicatives and Selective Applicatives?

Read on!

chrispenner.ca/posts/expres...
Monads are too powerful: The Expressiveness Spectrum
Monads are a useful tool, but what costs do we pay for their expressive power?
chrispenner.ca
September 27, 2025 at 4:02 AM
Reposted by Abhinav Sarkar
I wrote up a retrospective explaining why I ended my Nix Steering Committee term one year early

www.haskellforall.com/2025/09/stee...
Steering Committee Retrospective
Steering Committee Retrospective I am voluntarily ending my Steering Committee term early (I am only serving...
www.haskellforall.com
September 17, 2025 at 8:14 PM
Reposted by Abhinav Sarkar
How do first-class functions look up the value of a variable from an outer scope? Learn about referencing environments, closures, and macros in my latest Programming Language Pragmatics video!

PLP 3.6-3.7: Referencing Environments, Closures, and Macros - youtu.be/JBs4dY9nwOY
PLP 3.6-3.7: Referencing Environments, Closures, and Macros
YouTube video by Jonathan Aldrich
youtu.be
September 12, 2025 at 1:16 PM
Reposted by Abhinav Sarkar
If you write a raytracer in Haskell, the camera must always point in the positive Y direction.

This is because Haskell doesn't allow downcasting.
September 12, 2025 at 7:23 PM
Reposted by Abhinav Sarkar
I've been poking Srihari, our most experienced engineer @nilenso.com to share his hard-earned knowledge for the benefit of others.

Even if you're not an engineering leader like me, this checklist gives a lot of insight into what makes a great engineering org.

blog.nilenso.com/blog/2025/09...
September 12, 2025 at 6:32 AM
Reposted by Abhinav Sarkar
functional programmers never beating the “mostly write compilers” allegations
September 10, 2025 at 10:48 AM
Reposted by Abhinav Sarkar
Once again, the problem is that people ignore all of the invisible costs of vibe coding:

- prompting (specifying what to do *takes time*)
- learned helplessness
- constantly interrupting their own flow state
- babysitting rules files
- reviewing the LLM's output
- fixing bugs introduced by the LLM
July 21, 2025 at 3:32 PM