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•6mo ago

Comments

sshine•6mo 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_•6mo 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•6mo 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•6mo ago

    newtype Parser a = Parser ([Word] -> (a, [Word])
missing a paren here
moomin•6mo ago
I’m honestly completely failing to understand the basic idea here. What does this look like for generating and shrinking random strings,
chriswarbo•6mo 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•6mo 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•6mo 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•6mo 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•6mo 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•6mo 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•6mo 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•6mo 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•6mo 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•6mo 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•6mo 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•6mo 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.

Synadia and TigerBeetle Commit $512k USD to the Zig Software Foundation

https://www.synadia.com/blog/synadia-tigerbeetle-zig-foundation-pledge
164•derekcollison•2h ago•28 comments

Making a micro Linux distro (2023)

https://popovicu.com/posts/making-a-micro-linux-distro/
51•turrini•2h ago•13 comments

DNA reveals the real killers that brought down Napoleon's army

https://www.gavi.org/vaccineswork/dna-reveals-real-killers-brought-down-napoleons-army
28•janandonly•2h ago•33 comments

React vs. Backbone in 2025

https://backbonenotbad.hyperclay.com/
165•mjsu•5h ago•126 comments

The future of Python web services looks GIL-free

https://blog.baro.dev/p/the-future-of-python-web-services-looks-gil-free
61•gi0baro-dev•6d ago•15 comments

Unlocking free WiFi on British Airways

https://www.saxrag.com/tech/reversing/2025/06/01/BAWiFi.html
441•vinhnx•1d ago•101 comments

The Swift SDK for Android

https://www.swift.org/blog/nightly-swift-sdk-for-android/
600•gok•19h ago•239 comments

People with blindness can read again after retinal implant and special glasses

https://www.nbcnews.com/health/health-news/tiny-eye-implant-special-glasses-legally-blind-patient...
209•8bitsrule•4d ago•60 comments

Valetudo: Cloud replacement for vacuum robots enabling local-only operation

https://valetudo.cloud/
343•freetonik•5d ago•141 comments

First shape found that can't pass through itself

https://www.quantamagazine.org/first-shape-found-that-cant-pass-through-itself-20251024/
473•fleahunter•1d ago•130 comments

Key IOCs for Pegasus and Predator Spyware Removed with iOS 26 Update

https://iverify.io/blog/key-iocs-for-pegasus-and-predator-spyware-cleaned-with-ios-26-update
138•transpute•13h ago•83 comments

Study: MRI contrast agent causes harmful metal buildup in some patients

https://www.ormanager.com/briefs/study-mri-contrast-agent-causes-harmful-metal-buildup-in-some-pa...
189•nikolay•18h ago•162 comments

Context engineering is sleeping on the humble hyperlink

https://mbleigh.dev/posts/context-engineering-with-links/
131•mbleigh•2d ago•56 comments

The State of Machine Learning Frameworks in 2019

https://thegradient.pub/state-of-ml-frameworks-2019-pytorch-dominates-research-tensorflow-dominat...
9•jxmorris12•3d ago•4 comments

Harnessing America's heat pump moment

https://www.heatpumped.org/p/harnessing-america-s-heat-pump-moment
187•ssuds•19h ago•386 comments

What is intelligence? (2024)

https://whatisintelligence.antikythera.org/
123•sva_•14h ago•75 comments

I invited strangers to message me through a receipt printer

https://aschmelyun.com/blog/i-invited-strangers-to-message-me-through-a-receipt-printer/
249•chrisdemarco•6d ago•96 comments

Windows 10 Deadline Boosts Mac Sales

https://www.macrumors.com/2025/10/25/windows-10-deadline-boosts-mac-sales/
4•akyuu•7m ago•0 comments

Public Montessori programs strengthen learning outcomes at lower costs: study

https://phys.org/news/2025-10-national-montessori-early-outcomes-sharply.html
330•strict9•2d ago•194 comments

The persistence of tradition: the curious case of Henry Symeonis (2023)

https://blogs.bodleian.ox.ac.uk/archivesandmanuscripts/2023/12/13/the-persistence-of-tradition-th...
21•georgecmu•3d ago•0 comments

The geometry of mathematical methods

https://books.physics.oregonstate.edu/GMM/book.html
49•kalind•5d ago•3 comments

Code like a surgeon

https://www.geoffreylitt.com/2025/10/24/code-like-a-surgeon
198•simonw•1d ago•108 comments

Diamond Thermal Conductivity: A New Era in Chip Cooling

https://spectrum.ieee.org/diamond-thermal-conductivity
41•rbanffy•4d ago•17 comments

Meet the real screen addicts: the elderly

https://www.economist.com/international/2025/10/23/meet-the-real-screen-addicts-the-elderly
210•johntfella•11h ago•211 comments

Twake Drive – An open-source alternative to Google Drive

https://github.com/linagora/twake-drive
340•javatuts•1d ago•199 comments

Xubuntu website hacked and served malware

https://old.reddit.com/r/xubuntu/comments/1oa43gt/xubuntuorg_might_be_compromised/
5•28304283409234•24m ago•1 comments

Euro cops take down cybercrime network with 49M fake accounts

https://www.itnews.com.au/news/euro-cops-take-down-cybercrime-network-with-49-million-fake-accoun...
113•ubutler•8h ago•54 comments

Why formalize mathematics – more than catching errors

https://rkirov.github.io/posts/why_lean/
203•birdculture•6d ago•69 comments

How to make a Smith chart

https://www.johndcook.com/blog/2025/10/23/smith-chart/
147•tzury•22h ago•26 comments

Luau's performance

https://luau.org/performance
46•todsacerdoti•2d ago•10 comments