code-conjure: conjure Haskell functions out of partial definitions

[ bsd3, haskell, library ] [ Propose Tags ]

Conjure is a tool that produces Haskell functions out of partial definitions.

This is currently an experimental tool in its early stages, don't expect much from its current version. It is just a piece of curiosity in its current state.


[Skip to Readme]

Downloads

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees

Candidates

Versions [RSS] 0.0.2, 0.0.4, 0.1.0, 0.1.2, 0.2.0, 0.2.2, 0.2.4, 0.2.6, 0.2.8, 0.3.0, 0.3.2, 0.3.4, 0.3.6, 0.4.0, 0.4.2, 0.4.4, 0.5.0, 0.5.2, 0.5.4, 0.5.6, 0.5.8, 0.5.10, 0.5.12, 0.5.14
Change log changelog.md
Dependencies base (>=4 && <5), express (>=1.0.6), leancheck (>=0.9.10), speculate (>=0.4.14), template-haskell [details]
License BSD-3-Clause
Author Rudy Matela
Maintainer Rudy Matela <rudy@matela.com.br>
Category Haskell
Home page https://github.com/rudymatela/conjure#readme
Source repo head: git clone https://github.com/rudymatela/conjure
this: git clone https://github.com/rudymatela/conjure(tag v0.4.4)
Uploaded by rudymatela at 2021-09-02T18:00:02Z
Distributions LTSHaskell:0.5.14, NixOS:0.5.8, Stackage:0.5.14
Downloads 3595 total (66 in the last 30 days)
Rating (no votes yet) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs available [build log]
Last success reported on 2021-09-02 [all 1 reports]

Readme for code-conjure-0.4.4

[back to package description]

Conjure

Conjure's Build Status Conjure on Hackage Conjure on Stackage LTS Conjure on Stackage Nightly

Conjure logo

Conjure is a tool that produces Haskell functions out of partial definitions.

This is currently an experimental tool in its early stages, don't expect much from its current version. It is just a piece of curiosity in its current state.

Installing

To install the latest Conjure version from Hackage, just run:

$ cabal update
$ cabal v1-install code-conjure

If you are using Cabal v3.0 or later, avoid using cabal install for the time being and use v1-install instead.

Prerequisites are express, leancheck and speculate. They should be automatically resolved and installed by Cabal.

NOTE: the name of the Hackage package is code-conjure -- not to be confused with Conjure the BitTorrent client.

Conjuring functions

You first need to import the library with:

import Conjure

Then, given

square :: Int -> Int
square 0  =  0
square 1  =  1
square 2  =  4

and

primitives :: [Prim]
primitives  =  [ pr (0::Int)
               , pr (1::Int)
               , prim "+" ((+) :: Int -> Int -> Int)
               , prim "*" ((*) :: Int -> Int -> Int)
               ]

running

> conjure "square" square primitives

yields

square :: Int -> Int
-- testing 3 combinations of argument values
-- pruning with 14/25 rules
-- looking through 3 candidates of size 1
-- looking through 4 candidates of size 2
-- looking through 9 candidates of size 3
square x  =  x * x

in less than a second.

See the eg/arith.hs example.

Conjuring recursive functions

Given

factorial :: Int -> Int
factorial 1  =  1
factorial 2  =  2
factorial 3  =  6
factorial 4  =  24

and

primitives :: [Prim]
primitives  =  [ pr (0::Int)
               , pr (1::Int)
               , prim "+" ((+) :: Int -> Int -> Int)
               , prim "*" ((*) :: Int -> Int -> Int)
               , prim "-" ((-) :: Int -> Int -> Int)
               ]

running

> conjure "factorial" factorial primitives

yields

factorial :: Int -> Int
-- testing 4 combinations of argument values
-- pruning with 27/65 rules
-- looking through 3 candidates of size 1
-- looking through 4 candidates of size 2
-- looking through 13 candidates of size 3
-- looking through 34 candidates of size 4
-- looking through 75 candidates of size 5
-- looking through 183 candidates of size 6
-- looking through 577 candidates of size 7
factorial 0  =  1
factorial x  =  x * factorial (x - 1)

in less than a second.

It is also possible to generate

factorial x  =  foldr (*) 1 [1..x]

by including enumFromTo and foldr in the background.

See the eg/factorial.hs example.

MagicHaskeller (2007) is another tool that is able to generate Haskell code automatically. It supports recursion through catamorphisms, paramorphisms and the fix function. It is more mature than Conjure and is several orders of magnitude faster.

Barliman for Lisp is another tool that does program synthesis.

There are hundreds of others, I'll add the most closely related here when I have the time.

Further reading

For a detailed documentation of each function, see Conjure's Haddock documentation.

Conjure, Copyright 2021 Rudy Matela, distribued under the 3-clause BSD license.