Skip to content

Instantly share code, notes, and snippets.

@vasily-kirichenko
Last active August 29, 2015 13:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vasily-kirichenko/8840989 to your computer and use it in GitHub Desktop.
Save vasily-kirichenko/8840989 to your computer and use it in GitHub Desktop.
open FsCheck
type Tree<'a> =
| Branch of 'a * Tree<'a> * Tree<'a>
| Empty
let associativity (x: Tree<int>, F(_, f: Tree<int> -> float), F(_, g: float -> char), F(_, h: char -> int)) =
((f >> g) >> h) x = (f >> (g >> h)) x + 1 // let it fail
Check.Quick associativity
// Falsifiable, after 1 test (4 shrinks) (StdGen (1177772306,295822005)):
// (Empty, { Branch (0,Empty,Empty)->2.0; Empty->2.0 }, { 2.0->'a' }, { 'a'->0 })
// Translated from http://hackage.haskell.org/package/QuickCheck-2.4.1.1/docs/Test-QuickCheck-Function.html
let prop (F (_, f)) = f "monkey" = f "banana" || f "banana" = f "elephant"
// val prop : Function<string,'a> -> bool when 'a : equality
Check.Verbose prop
// ...
// 97:
// { "banana"->"*B_NUwC9"; "monkey"->"*B_NUwC9" }
// 98:
// { "banana"->false; "monkey"->false }
// 99:
// { "banana"->'o'; "monkey"->'o' }
// Ok, passed 100 tests.
@jessitron
Copy link

wait, wasn't the monkey-banana-elephant property supposed to be falsified?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment