Friday, August 22, 2025

Uncertain⟨T⟩

Mattt Thompson:

In 2014, researchers at the University of Washington and Microsoft Research proposed a radical idea: What if uncertainty were encoded directly into the type system? Their paper, Uncertain<T>: A First-Order Type for Uncertain Data introduced a probabilistic programming approach that’s both mathematically rigorous and surprisingly practical.

As you’d expect for something from Microsoft in the 2010s, the paper is implemented in C#. But the concepts translate beautifully to Swift.

[…]

When you compare two Uncertain values, you don’t get a definitive true or false. You get an Uncertain<Bool> that represents the probability of the comparison being true.

[…]

Using an abstraction like Uncertain<T> forces you to deal with uncertainty as a first-class concept rather than pretending it doesn’t exist. And in doing so, you end up with much smarter code.

7 Comments RSS · Twitter · Mastodon


Written by Matt

Can this behavior be extended? Like can you daisy chain comparisons and get a likelihood? This is really interesting, like I wonder if you’d need different underlying structure depending on if you were using a Bayesian or frequentist approach. Would love to try something like this in python.


Oh dear, I tried to make a joke that I was written by Matt[t] (like the name of the software) but I didn’t realize the comment was interpreted so it didn’t show up 😂


To point out a fairly random but interesting adjacency, the linguist George Lakoff wrote his MIT PhD thesis (Chomsky was his supervisor) on “hedges” in language. He tried to assign a quantifiable weight to the relative uncertainties of “I’ll probably have lunch” vs “I’ll likely have lunch” vs “I’ll maybe have lunch.” Slightly different realization of that work here - https://www.jstor.org/stable/pdf/30226076.pdf


This reminds me strongly of the equally useful probabilistic spreadsheet, which uses a same approach of replacing numbers in cells with statistical variables:

https://blog.singleton.io/posts/2021-11-24-probabilistic-spreadsheet/


@Tomas Kafka – This is great. You should check out Risk Solver Platform, which does something similar for Excel. With Lambdas, we can do some of the same thing natively now, but I think getting a real monte carlo analysis is still not possible.



Another related tool is Filip Hracek's Unsure Calculator, which I could have sworn I found out about recently on this very site, but perhaps not...

https://filiph.github.io/unsure/

Leave a Comment