[Haskell-cafe] Purely logical programming language

Lauri Alanko la at iki.fi
Tue May 26 15:24:41 EDT 2009

On Tue, May 26, 2009 at 09:10:10PM +0200, Matthias Görgens wrote:
> The model in Prolog, however, looks more like the model used in most
> strict functional languages.  It uses impure predicates to affect the
> outside world.  Do you know of any attempt to do for logic programming
> what Monads did for functional programming?

Traditionally Prolog programmers have used chained state variables:

foo(X,S0,SOut) :- bar(X,S0,S1), baz(X,Y,S1,S2), quux(X,Y,S2,SOut).

This is kind of like using a state monad on top of Prolog's built-in
nondeterminism monad. There's even syntactic sugar for this, just like
Haskell programmers have the do-syntax:

foo(X) --> bar(X), baz(X,Y), quux(X,Y).

Although Prolog isn't pure, Mercury, its derivative, is (mostly). In
Mercury, the "IO state" (kind of like RealWorld) is threaded through
state variables and Mercury's mode checking makes sure that there will
always be only one result from IO predicates.

Mercury also has type classes and other Haskellisms, so if you're
interested in "doing Prolog the Haskell way", you should definitely
have a look at it.


More information about the Haskell-Cafe mailing list