A logic programming library for F#
F#
Latest commit 5af73f6 Apr 4, 2015 @palladin appendo example
Permalink
Failed to load latest commit information.
src appendo example Apr 4, 2015
.gitattributes Basic code structure Mar 25, 2015
.gitignore Basic code structure Mar 25, 2015
README.md Update README.md Mar 22, 2015

README.md

logic

A logic programming library for F# based on miniKanren and μKanren. It is designed to offer an idiomatic F# programming style and also resemble the scheme version of miniKanren.

Example

The peano function in Scheme-miniKanren

(define peano
  (lambda (n)
    (conde
     ((== 'z n))
     ((fresh (n-)
             (== `(s. ,n-) n)
             (peano n-))))))

(run 3 (q) (peano q)) ;; '(z (s. z) (s. (s. z)))

the F# version is pretty similar

let rec peano n =
    logic {
        do! conde [ Str "z" == n;
                    logic {
                        let! n' = fresh
                        do! Pair (Str "s", n') == n
                        return! peano n'
                    } ]
    }

run 3 (fun q -> peano q) //  [Str "z"; Pair (Str "s",Str "z"); Pair (Str "s",Pair (Str "s",Str "z"))]

The Reasoned Schemer

For the functional programmer who wants to learn to think logically there is no better introduction than The Reasoned Schemer.

alt text