| CARVIEW |
Select Language
HTTP/2 200
alt-svc: h3=":443"; ma=2592000
cache-control: max-age=0, private, must-revalidate
content-encoding: gzip
content-security-policy: default-src 'none'; connect-src 'self'; img-src 'self' data: ; script-src 'self' 'nonce-wnYYvCIqg62uwvUD3RZxcg=='; style-src 'self' 'unsafe-inline'
content-type: text/html; charset=utf-8
etag: W/"b4392aae0be753a35ad765dcaea8aceb"
feature-policy: accelerometer 'none'; autoplay 'none'; ambient-light-sensor 'none'; camera 'none'; encrypted-media 'none'; fullscreen 'none'; geolocation 'none'; gyroscope 'none'; idle-detection 'none'; magnetometer 'none'; microphone 'none'; midi 'none'; payment 'none'; picture-in-picture 'none'; screen-wake-lock 'none'; serial 'none'; sync-xhr 'none'; usb 'none'; web-share 'none'
link: ; rel=preload; as=style; nopush,; rel=preload; as=style; nopush,; rel=preload; as=style; nopush,; rel=preload; as=style; nopush
referrer-policy: strict-origin-when-cross-origin
strict-transport-security: max-age=31536000
strict-transport-security: max-age=63072000; includeSubDomains; preload
vary: Accept
vary: Accept-Encoding
via: 1.1 Caddy
x-content-type-options: nosniff
x-frame-options: SAMEORIGIN
x-permitted-cross-domain-policies: none
x-request-id: 09737626-190a-4377-a6e8-faabc6eac914
x-xss-protection: 0
date: Fri, 16 Jan 2026 15:02:50 GMT
Statically Typed Functional Programming with Python 3.12 | Lobsters
So both Python and Java have ADTs now. It's frankly shameful that Go does not.
A real shame that Googlers are not capable of understanding a brilliant language
That would definitely make me consider Go again, at least.
Nice post! Yes I did notice that with
You can now write OCaml/Rust-ish code in Python :) I can definitely see that some people will find it ugly, and I might have had that opinion 10 years ago.
But I find it is pretty fun and easy to write little compilers and evaluators in this style. The style depends on the problem you're solving, maybe even more than the language you're writing in.
A few months ago I hand-translated a Rust program from BurntSushi to Python, and it's all statically typed. It works pretty well, and the code is pretty much a direct translation, one-for-one.
https://github.com/andychu/rsc-regexp/tree/master/py (the Rust program being in turn hand-translated from a C program)
This is also kinda how Oils is written, with the added benefit that we automatically translate the program to C++, for a predictable 30x-50x speeedup.
We use a schema language Zephyr ASDL to express algebraic data types, not the verbose
dataclassstuff. And we have an idiom forswitchusing thewithstatement.A bit off-topic perhaps, but I browsed quickly through the code you linked and lines 283-312 caught my eye: Maybe a dumb question :), but what exactly does the following part do?
Was not aware that you can also provide a string to Optional. Does it somehow "forward-declare" the type State you define a few lines later and the string gets later matched to the actual type?
That's right. And with the new
typestatement you don't have to use strings to do forward declarations.Technically it hasn’t been needed since 3.7 because you can enable
from __future__ import annotationswhich makes all annotations lazy. Although for type aliases you need to combine it withtyping.TYPE_CHECKING.Thank you!
I didn't know about the ASDL stuff and how it's used in CPython, thanks for sharing!
(Apologize for tangential comment)
I've added a feed now at https://wickstrom.tech/feed.xml
Thank you, subscribed.
I think most non-pl crowd will have a hard time expressing their thinking in "linear temporal logic formulae". Llms could potentially serve as a translation layer for " I want to ensure certain website behavior" into your dsl to ease people into your way of modeling problems
That's a very interesting idea. I should try it out!
Some prompt tuning and I got chatgpt to spit out a very basic but working spec. I guess one could loop and feed it parser errors until it's valid. Would be interesting then to make the whole experience interactive, i.e. that you have a back-and-forth with the system to refine the spec, getting counter-examples back from Quickstrom, accepting or rejecting them as valid behavior, running new tests, and so on. I'd like to try this with a local model some time as well.
[Comment from banned user removed]
The author is using Python 3.12 features (afaik the only 3.12 feature is
typekeyword but still) to demonstrate parsing custom constructs for some hypothetical language. They are not actually expecting you to useIf,LetorBinOpin your own code as replacements for Python language features.It is a cool example and it makes me want to go back to Building An Interpreter In Go, which I did in Python a while ago.
What are the custom constructs in their example code?
on the contrary, pattern matching on algebraic types is both very natural and pays off "at scale".
[Comment removed by author]
So you missed the point and noped out based on that?
[Comment removed by author]