John Hughes - Building on developers' intuitions (...) | Lambda Days 19

แชร์
ฝัง
  • เผยแพร่เมื่อ 16 ต.ค. 2024

ความคิดเห็น • 5

  • @knownfleece5125
    @knownfleece5125 4 ปีที่แล้ว

    Oh, I didn't know I could use QuickCheck to help me come up with missing unit tests. So nice!

  • @tepan
    @tepan 5 ปีที่แล้ว +1

    Thanks for the video! I'm trying the QuickCheck example for the first time:
    λ> quickCheck $ \xs -> reverse xs === xs
    +++ OK, passed 100 tests.
    I tried it multiple times. Somehow QuickCheck runs through 100 happy cases. :( How come?
    Other examples work better:
    λ> quickCheck $
    -> sqrt(n^2) === n
    *** Failed! Falsifiable (after 7 tests and 4 shrinks):
    -1.0
    1.0 /= -1.0
    λ> quickCheck $
    -> sqrt(n^2) === abs n
    +++ OK, passed 100 tests.

    • @Almanildo
      @Almanildo 5 ปีที่แล้ว +2

      I am not the speaker, but the answer to your question is related to polymorphism. Your list xs has a polymorphic type [a], which quickCheck defaults to [()], that is a list of units (). Since there is only one value of type (), reverse xs == xs always succeeds.
      Specializing the type to [Int] fails:
      > quickCheck $ \xs -> (reverse xs :: [Int]) == xs
      *** Failed! Falsifiable (after 5 tests and 1 shrink):
      [0,1]
      I agree that it's confusing, though.

    • @LyndonMaydwell
      @LyndonMaydwell 4 ปีที่แล้ว

      Check what the instance being used is for the list elements is!

  • @JakeMitchell_mekajfire
    @JakeMitchell_mekajfire 5 ปีที่แล้ว +1

    Wonderful talk! I reproduced the examples and verified they behave as expected: github.com/jmitchell/developers-intuition.hs