frontpage.
newsnewestaskshowjobs

Made with ♥ by @iamnishanth

Open Source @Github

fp.

Open in hackernews

Falsify: Hypothesis-Inspired Shrinking for Haskell (2023)

https://www.well-typed.com/blog/2023/04/falsify/
90•birdculture•8mo ago

Comments

sshine•8mo ago
How does Hedgehog and Hypothesis differ in their shrinking strategies?

The article uses the words "integrated" vs. "internal" shrinking.

> the raison d’être of internal shrinking: it doesn’t matter that we cannot shrink the two generators independently, because we are not shrinking generators! Instead, we just shrink the samples that feed into those generators.

Besides that it seems like falsify has many of the same features like choice of ranges and distributions.

_jackdk_•8mo ago
This is the key sentence:

> The key insight of the Hypothesis library is that instead of shrinking generated values, we instead shrink the samples produced by the PRNG.

Hedgehog loses shrink information when you do a monadic bind (Gen a -> (a -> Gen b) -> Gen b). Hypothesis parses values out of the stream of data generated by the PRNG, so when it "binds", you are still just consuming off that stream of random numbers, and you can shrink the stream to shrink the generated values.

Here is a talk that applies the Hypothesis idea to test C++: https://www.youtube.com/watch?v=C6joICx1XMY . Discussion of PBT implementation approaches begins at 6:30.

thesz•8mo ago
This is fascinating!

If I understand correctly, they approximate language of inputs of a function to discover minimal (in some sense, like "shortest description length") inputs that violate relations between inputs and outputs of a function under scrutiny.

evertedsphere•8mo ago

    newtype Parser a = Parser ([Word] -> (a, [Word])
missing a paren here
moomin•8mo ago
I’m honestly completely failing to understand the basic idea here. What does this look like for generating and shrinking random strings,
chriswarbo•8mo ago
One straightforward approach would be:

- Generate a random number N for the size (maybe restricted to some Range)

- Generate N `Char` values, by using a random number for each code point.

- Combine those Chars into a string

falsify runs a generator by applying it to an infinite binary tree, with random numbers in the nodes. A generator can either consume a single number (taken from the root node of a tree), or it can run two other generators (one gets run on the left child, the other gets run on the right). Hence the above generator would use the value in the left child as N, then run the "generate N Chars" generator on the right child. The latter generator would run a Char generator on its left child, and an 'N-1 Chars' generator on its right child; and so on.

To shrink, we just run the generator on a tree with smaller numbers. In this case, a smaller number in the left child will cause fewer Chars to be generated; and smaller numbers in the right tree will cause lower code-points to be generated. falsify's tree representation also has a special case for the smallest tree (which returns 0 for its root, and itself for each child).

mjw1007•8mo ago
I've found in practice that shrinking to get the "smallest amount of detail" is often unhelpful.

Suppose I have a function which takes four string parameters, and I have a bug which means it crashes if the third is empty.

I'd rather see this in the failure report:

("ldiuhuh!skdfh", "nd#lkgjdflkgdfg", "", "dc9ofugdl ifugidlugfoidufog")

than this:

("", "", "", "")

gwern•8mo ago
Really? Your examples seem the opposite. I am left immediately thinking, "hm, is it failing on a '!', some sort of shell issue? Or is it truncating the string on '#', maybe? Or wait, there's a space in the third one, that looks pretty dangerous, as well as noticeably longer so there could be a length issue..." As opposed to the shrunk version where I immediately think, "uh oh: one of them is not handling an empty input correctly." Also, way easier to read, copy-paste, and type.
dullcrisp•8mo ago
Their point is that in the unshrunk example the “special” value stands out.

I guess if we were even more clever we could get to something more like (…, …, "", …).

gwern•8mo ago
The special value doesn't stand out, though. All three examples I gave were what I thought skimming his comment before my brain caught up to his caveat about an empty third argument. The empty string looked like it was by far the most harmless part... Whereas if they are all empty strings, then by definition the empty string stands out as the most suspicious possible part.
tybug•8mo ago
The Hypothesis explain phase [1][2] does this!

  fails_on_empty_third_arg(
      a = "",  # or any other generated value
      b = "",  # or any other generated value
      c = "",  
      d = "",  # or any other generated value
  )
[1] https://hypothesis.readthedocs.io/en/latest/reference/api.ht...

[2] https://github.com/HypothesisWorks/hypothesis/pull/3555

chriswarbo•8mo ago
> As opposed to the shrunk version where I immediately think, "uh oh: one of them is not handling an empty input correctly."

I agree that non-empty strings are worse, but unfortunately `("", "", "", "")` wouldn't only make me think of empty strings; e.g. I'd wonder whether duplicate/equal values are the problem.

chriswarbo•8mo ago
> I'd rather see this in the failure report:

> ("ldiuhuh!skdfh", "nd#lkgjdflkgdfg", "", "dc9ofugdl ifugidlugfoidufog")

I would prefer LazySmallcheck's result, which would be the following:

    (_, _, "", _)
Where `_` indicates that part of the input wasn't evaluated.
yorwba•8mo ago
A minimal reproducing example cannot guarantee that you'll correctly diagnose a bug just by looking at the example (because multiple potential bugs could cause the same example to fail) but it can guarantee that when you step through the code to understand what's happening, you won't have to deal with huge amounts of irrelevant data.

Maybe an alternative shrinking procedure could directly minimize the number of instructions that need to be executed to hit a failure...

edsko•8mo ago
(Author of falsify here.) You are absolutely correct that the empty string isn't always the best counter-example. The goal of shrinking is to shrink to the _simplest_ possible value (this is true for all approaches to shrinking). What constitutes "simple" is very much domain specific. It would certainly be possible to write a generator that would shrink to, say, "foo", as the canonical "simplest" example of a simple string. Indeed, since we are working in a lazy language, you could (with a bit of effort) shrink to `undefined` if the other arguments are not used at all.
mjw1007•8mo ago
I agree it can be domain-specific, but I think it's more common than not that empty containers, and the number zero, are corner cases rather than typical values.

So I think it would be a decent quality-of-life improvement to make generators of the sort you suggest easily available, and have the tutorial docs use them from the start.

shae•8mo ago
I care about the edge between "this value fails, one value over succeeds". I wish shrinking were fast enough to tell me if there are multiple edges between those values.

Claude Cowork Exfiltrates Files

https://www.promptarmor.com/resources/claude-cowork-exfiltrates-files
407•takira•5h ago•172 comments

Furiosa: 3.5x efficiency over H100s

https://furiosa.ai/blog/introducing-rngd-server-efficient-ai-inference-at-data-center-scale
23•written-beyond•23m ago•1 comments

Anthropic Explicitly Blocking OpenCode

https://gist.github.com/R44VC0RP/bd391f6a23185c0fed6c6b5fb2bac50e
73•ryanvogel•1h ago•42 comments

Scaling long-running autonomous coding

https://cursor.com/blog/scaling-agents
93•samwillis•2h ago•56 comments

The State of OpenSSL for pyca/cryptography

https://cryptography.io/en/latest/statements/state-of-openssl/
61•SGran•3h ago•14 comments

Ask HN: Share your personal website

385•susam•8h ago•1247 comments

Show HN: WebTiles – create a tiny 250x250 website with neighbors around you

https://webtiles.kicya.net/
108•dimden•5d ago•15 comments

Sun Position Calculator

https://drajmarsh.bitbucket.io/earthsun.html
55•sanbor•3h ago•12 comments

Billion-Dollar Idea Generator

https://www.pivotgpt.ceo/
12•greenRust•1h ago•5 comments

Why some clothes shrink in the wash and how to unshrink them

https://www.swinburne.edu.au/news/2025/08/why-some-clothes-shrink-in-the-wash-and-how-to-unshrink...
429•OptionOfT•3d ago•236 comments

Generate QR Codes with Pure SQL in PostgreSQL

https://tanelpoder.com/posts/generate-qr-code-with-pure-sql-in-postgres/
36•tanelpoder•4d ago•1 comments

SparkFun Officially Dropping AdaFruit due to CoC Violation

https://www.sparkfun.com/official-response
379•yaleman•10h ago•373 comments

Roam 50GB is now Roam 100GB

https://starlink.com/support/article/58c9c8b7-474e-246f-7e3c-06db3221d34d
244•bahmboo•9h ago•274 comments

ChromaDB Explorer

https://www.chroma-explorer.com/
20•arsentjev•2h ago•1 comments

Find a pub that needs you

https://www.ismypubfucked.com/
208•thinkingemote•9h ago•168 comments

I hate GitHub Actions with passion

https://xlii.space/eng/i-hate-github-actions-with-passion/
413•xlii•14h ago•296 comments

Native ZFS VDEV for Object Storage (OpenZFS Summit)

https://www.zettalane.com/blog/openzfs-summit-2025-mayanas-objbacker.html
84•suprasam•6h ago•18 comments

Show HN: Webctl – Browser automation for agents based on CLI instead of MCP

https://github.com/cosinusalpha/webctl
57•cosinusalpha•10h ago•17 comments

Ford F-150 Lightning outsold the Cybertruck and was then canceled for poor sales

https://electrek.co/2026/01/13/ford-f150-lightning-outsold-tesla-cybertruck-canceled-not-selling-...
424•MBCook•7h ago•578 comments

How can I build a simple pulse generator to demonstrate transmission lines

https://electronics.stackexchange.com/questions/764155/how-can-i-build-a-simple-pulse-generator-t...
4•alphabetter•5d ago•0 comments

Rubik's Cube in Prolog – Order

https://medium.com/@kenichisasagawa/i-am-preparing-material-for-a-prolog-book-af7580acfee7
13•myth_drannon•4d ago•3 comments

The hunt for a stolen Jackson Pollock

https://www.washingtonpost.com/entertainment/art/interactive/2026/jackson-pollock-theft-isaacs-fa...
14•prismatic•16h ago•0 comments

Ask HN: How do you safely give LLMs SSH/DB access?

54•nico•6h ago•78 comments

Is Rust faster than C?

https://steveklabnik.com/writing/is-rust-faster-than-c/
219•vincentchau•4d ago•250 comments

GitHub should charge everyone $1 more per month to fund open source

https://blog.greg.technology/2025/11/27/github-should-charge-1-dollar-more-per-month.html
212•evakhoury•8h ago•201 comments

Ski map artist James Niehues, the 'Monet of the mountains' (2021)

https://adventure.com/ski-map-artist-james-niehues/
114•gyomu•4d ago•13 comments

Every country should set 16 as the minimum age for social media accounts

https://www.afterbabel.com/p/why-every-country-should-set-16
136•paulpauper•5h ago•189 comments

So, you’ve hit an age gate. What now?

https://www.eff.org/deeplinks/2026/01/so-youve-hit-age-gate-what-now
290•hn_acker•7h ago•229 comments

I’m leaving Redis for SolidQueue

https://www.simplethread.com/redis-solidqueue/
296•amalinovic•15h ago•124 comments

Lago (Open-Source Billing) is hiring across teams and geos

1•Rafsark•12h ago