haltavista - look for functions by example

Hello, I just hacked together something I've been talking about a while ago on that mailing list. It's a program that looks for functions given a set of input/outputs. Example session 1: brauner@worf:~$ haltavista 2 2 4 <EOF> Prelude (*) Prelude (+) Prelude (^) Example session 2 (refining previous search): brauner@worf:~$ haltavista 2 2 4 1 2 3 <EOF> Prelude (+) Example session 3 (higher-order functions): brauner@worf:~$ haltavista (+1) (+2) (1,1) (2,3) <EOF> Data.Graph.Inductive.Query.Monad (><) Under the hood, uses: - hint for type inference; - hoogle to get a list of candidate functions; - hint for testing. Hoogle calling facility has been copy-pasted (and later modified) from the Yi project. It's availaible on github (http://github.com/polux/haltavista) and I plan to release it on hackage as soon as I catch stack overflows that occur during testing using hint. So far I didn't manage to do it, even by catching asynchronous exceptions. Every suggestion/help is welcome. Also, if I got something wrong with the licences (Yi uses GPL-2 and code is copy-pasted, Hint BSD3 and is linked, Hoogle is called as an external process, haltavista is GPL-3 for now) please tell me. Paul

Hi, i'ts on hackage now. Thanks to Jun Inoue, stack overflows are now catched. Paul On Sat, Sep 18, 2010 at 11:47:07AM +0200, Paul Brauner wrote:
Hello,
I just hacked together something I've been talking about a while ago on that mailing list. It's a program that looks for functions given a set of input/outputs.
Example session 1:
brauner@worf:~$ haltavista 2 2 4 <EOF>
Prelude (*) Prelude (+) Prelude (^)
Example session 2 (refining previous search):
brauner@worf:~$ haltavista 2 2 4 1 2 3 <EOF>
Prelude (+)
Example session 3 (higher-order functions):
brauner@worf:~$ haltavista (+1) (+2) (1,1) (2,3) <EOF>
Data.Graph.Inductive.Query.Monad (><)
Under the hood, uses:
- hint for type inference; - hoogle to get a list of candidate functions; - hint for testing.
Hoogle calling facility has been copy-pasted (and later modified) from the Yi project.
It's availaible on github (http://github.com/polux/haltavista) and I plan to release it on hackage as soon as I catch stack overflows that occur during testing using hint. So far I didn't manage to do it, even by catching asynchronous exceptions. Every suggestion/help is welcome.
Also, if I got something wrong with the licences (Yi uses GPL-2 and code is copy-pasted, Hint BSD3 and is linked, Hoogle is called as an external process, haltavista is GPL-3 for now) please tell me.
Paul _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

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...

In my haste to reply I made an error in my 'newby' multiplication function. Pesky negative numbers... intMul ∷ Integer → Integer → Integer intMul x n | n < 0 = -(intMul x $ abs n) | n == 0 = 0 | n > 0 = x + intMul x (n - 1) I do wonder what happens when haltavista encounters a function that diverges. Like my original intMul applied to a negative number: "intMul 2 (-1)".

There's a timeout of 1.5 second right now.. On Sun, Sep 19, 2010 at 07:46:54PM +0200, Roel van Dijk wrote:
In my haste to reply I made an error in my 'newby' multiplication function. Pesky negative numbers...
intMul ∷ Integer → Integer → Integer intMul x n | n < 0 = -(intMul x $ abs n) | n == 0 = 0 | n > 0 = x + intMul x (n - 1)
I do wonder what happens when haltavista encounters a function that diverges. Like my original intMul applied to a negative number: "intMul 2 (-1)".

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...
participants (2)
-
Paul Brauner
-
Roel van Dijk