
It works: brauner@worf:/tmp$ cat test.hs import Test.QuickCheck import Test.QuickCheck.Arbitrary import Control.Monad(forM_) intMul :: Integer -> Integer -> Integer intMul x n | n < 0 = -(intMul x $ abs n) | n == 0 = 0 | n > 0 = x + intMul x (n - 1) main = do xs <- sample' arbitrary ys <- sample' arbitrary zip xs ys `forM_` \(x,y) -> putStrLn (show x ++ " " ++ show y ++ " " ++ (show $ intMul x y)) brauner@worf:/tmp$ runghc test.hs | haltavista Prelude (*) I will include this functionality in the next version. Thank you for this nice idea. Paul On Sun, Sep 19, 2010 at 08:16:08PM +0200, Paul Brauner wrote:
That's a great idea!
In the same vein, have you had a look at quickspec by Koen Claessen, Nicholas Smallbone and John Hughes?
www.cse.chalmers.se/~nicsma/quickspec.pdf
This reminds me of another idea, suggested by Jun inoue: look for functions by specification instead of examples.
I will try your idea ASAP. As you say, I think that might be helpful for beginners, as you suggest, or even when you're not a beginner anymore but you start using a new library.
Paul
On Sun, Sep 19, 2010 at 07:41:21PM +0200, Roel van Dijk wrote:
Very interesting!
It got me thinking: if you combine this with the Arbitrary class [1] of QuickCheck you can use it check if you have defined a function that is "equal" to an already defined function.
Let's say I write the following function:
intMul ∷ Integer → Integer → Integer intMul x 0 = 0 intMul x n = x + intMul x (n - 1)
No you can automatically apply this function to a list of 100 generated inputs to get a list of input output pairs. Feed this into haltavista and it should tell you that you can replace your definition with Prelude (*). While such an observation is certainly not a proof it is still useful.
It would be a nice addition to a Haskell editor. Especially for those new to the language.
Regards, Roel
1 - http://hackage.haskell.org/packages/archive/QuickCheck/2.3/doc/html/Test-Qui...