code-conjure: conjure Haskell functions out of partial definitions

This is a package candidate release! Here you can preview how this package release will appear once published to the main package index (which can be accomplished via the 'maintain' link below). Please note that once a package has been published to the main package index it cannot be undone! Please consult the package uploading documentation for more information.

[maintain] [Publish]

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]

Properties

Versions 0.0.2, 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
Change log None available
Dependencies base (==4.*), express (>=0.1.6), leancheck (>=0.9.4), speculate (>=0.4.6), 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/extrapolate
this: git clone https://github.com/rudymatela/extrapolate(tag v0.0.2)
Uploaded by rudymatela at 2021-04-24T18:38:16Z

Modules

[Index]

Downloads

Maintainer's Corner

For package maintainers and hackage trustees


Readme for code-conjure-0.0.2

[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 install code-conjure

Starting from Cabal v3.0, you need to pass --lib as an argument to cabal install:

$ cabal install code-conjure --lib

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

Given

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

and

background :: [Expr]
background =
  [ val (0::Int)
  , val (1::Int)
  , value "+" ((+) :: Int -> Int -> Int)
  , value "*" ((*) :: Int -> Int -> Int)
  , value "==" ((==) :: Int -> Int -> Bool)
  ]

running

> conjure "square" square background

yields

square :: Int -> Int
-- looking through 815 candidates, 100% match, 3/3 assignments
square x  =  x * x

in less than a second.

See the eg/arith.hs example.

Conjuring recursive functions

Given

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

and

background :: [Expr]
background  =
  [ val (0::Int)
  , val (1::Int)
  , value "+" ((+) :: Int -> Int -> Int)
  , value "*" ((*) :: Int -> Int -> Int)
  , value "dec" (subtract 1 :: Int -> Int)
  , value "isZero" ((==0) :: Int -> Bool)
  , val False
  , val True
  , ifFor (undefined :: Int)
  , value "==" ((==) :: Int -> Int -> Bool)
  ]

running

> conjure "factorial" factorial background

yields

factorial :: Int -> Int
-- looking through 9266 candidates, 100% match, 6/6 assignments
factorial x  =  if isZero x then 1 else x * factorial (dec x)

in about 3 seconds.

See the eg/factorial.hs example.

It is also possible to generate:

factorial x  =  if x == 0 then 1 else x * factorial x - 1

in about 30s by changing the background and increasing the size limit.

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 2020 Rudy Matela, distribued under the 3-clause BSD license.