(评论)
(comments)

原始链接: https://news.ycombinator.com/item?id=43746017

这篇 Hacker News 讨论帖讨论了 Falsify,一个新的 Haskell 属性测试库,它具有受 Hypothesis 启发的收缩功能。其核心概念是“内部收缩”,即收缩的是提供给生成器的样本,而不是生成器本身。 用户 sshine 询问了 Falsify 的收缩方法与 Hedgehog 和 Hypothesis 的区别。thesz 发现 Falsify 通过逼近函数输入的语言来寻找最小违反输入的方法“令人着迷”。 mjw1007 认为收缩到尽可能小的细节可能没有帮助,他更喜欢突出导致错误的特定输入的失败报告,即使该输入比较大。Gwern 反驳说,最小示例更容易理解和调试。dullcrisp 建议理想情况下,收缩应该隔离“特殊”值。shae 希望更快的收缩能够识别失败值和成功值之间的精确边界。该讨论帖还指出了代码片段中缺少的括号,moomin 则寻求 Falsify 如何处理字符串生成和收缩的澄清。

相关文章
  • (评论) 2025-04-21
  • (评论) 2025-04-07
  • (评论) 2025-03-22
  • (评论) 2025-03-28
  • (评论) 2025-04-08

  • 原文
    Hacker News new | past | comments | ask | show | jobs | submit login
    Falsify: Hypothesis-Inspired Shrinking for Haskell (2023) (well-typed.com)
    54 points by birdculture 6 hours ago | hide | past | favorite | 9 comments










    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.



    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.



    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:

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



    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.


    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 (…, …, "", …).



    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.


    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.


        newtype Parser a = Parser ([Word] -> (a, [Word])
    
    missing a paren here


    I’m honestly completely failing to understand the basic idea here. What does this look like for generating and shrinking random strings,






    Join us for AI Startup School this June 16-17 in San Francisco!


    Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact



    Search:
    联系我们 contact @ memedata.com