Coder Social home page Coder Social logo

acharal / hopes Goto Github PK

View Code? Open in Web Editor NEW
50.0 9.0 6.0 3.56 MB

Higher Order Prolog with Extensional Semantics

License: GNU General Public License v2.0

Haskell 88.99% Prolog 6.55% Makefile 1.06% Yacc 3.39%
hopes prolog interpreter higher-order-logic logic-programming

hopes's Introduction

HOPES: Higher-Order PROLOG with Extensional Semantics

GitHub license Build Status

HOPES is a prototype interpreter for a higher-order PROLOG-like language.

The syntax of the language extends that of PROLOG by supporting higher-order constructs (such as higher-order predicate variables, partial application and lambda terms). In particular, the syntax allows clauses (and queries) that contain uninstantiated predicate variables. The interpreter implements a higher-order top-down SLD-resolution proof procedure described in CKRW13 together with the semantics of the language.

HOPES has all the advantages of a higher-order system but continues to keep the flavor of classical PROLOG programming.

Introduction

In HOPES one can express popular functional operators such as map:

map(R,[],[]).
map(R,[X|Xs],[Y|Ys]) :- R(X,Y), map(R,Xs,Ys).

Apart from using functional operators in a logic programming context, we can also express naturally relational operators and graph operators:

join(R,Q)(X) :- R(X), Q(X).
union(R,Q)(X) :- R(X).
union(R,Q)(X) :- Q(X).
singleton(Y)(X) :- X = Y.
diff(R,Q)(X) :- R(X), not(Q(X)). 
tc(G)(X,Y) :- G(X,Y).
tc(G)(X,Y) :- G(X,Z), tc(G)(Z,Y).

The definition of higher-order predicates together with the use of partial applications can lead to a different programming style that blends the functional and the logic programming. The following HOPES snipset shows how we can define except (i.e. the predicate that succeeds for all elements of R except Y) by reusing (possibly) partially applied operators.

except(R,Y)(X) :- diff(R, singleton(Y)).

As in classical PROLOG it is not required to use in a query some variables as input and some variables as output. Along that lines, HOPES also support queries that may have unbound predicate variables. For example, one can query

?- tc(G)(a,b).

to ask for potential graphs G whose transitive closure contains (a,b). In that case the interpreter will systematically (and in a sophisticated way) investigate all finite instantiations of these variables. The answers will be sets that represent the extension of G even if no such predicate is currently defined in the program. For example, potential answers of the aforementioned query will be:

G = { (a,b) } ;
G = { (a,X1), (X1,b) } ;
G = { (a,X1), (X1,X2), (X2,b) };

Getting Started

Building HOPES

In order to build HOPES you must should install haskell stack.

$ curl -sSL https://get.haskellstack.org/ | sh
$ stack build

Note for Windows

Microsoft Windows compilations are not yet tested but there should be no problem as far as GHC and cabal are installed in the system.

Running some examples

In pl/examples directory there are some hopes examples to getting started. To load an example you must type

-? :l pl/examples/file.pl

hopes's People

Contributors

acharal avatar plaice avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

hopes's Issues

Successor relation s()

I loaded the mini-prelude:

hopes mini-prelude.pl

and typed in the repl:

nat(1).

getting the answer: No
I used the master branch.

Lucid Meets Prolog extension

Hi,
I read Lucid Meets Prolog on Bill Wadge's Blog and thought this sounds very useful.
I am quite new to prolog, so maybe I am missing something. Can this extension be implemented in Hopes?
Thanks,
Vincent

PS:
In your build script, there is the dependency for the happy parser missing.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.