Purely logical programming language

There are a number of ways to marry purely functional programming languages with IO. To name just two possibilities: Clean uses linear types, threading exactly one "World" through functions, Haskell uses Monads. 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?

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. Lauri

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.
Thanks. I'll have a look. (I also just found Mercury on my own: After I posed my original question, I tried another web search, and found what I was looking for. I haven't read the articles, yet, so I am grateful for your summary.)

Hi, On 26.05.2009, at 21:24, Lauri Alanko wrote:
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.
I have to admit that I am not very familiar with Mercury. But if you are looking for "doing Prolog the Haskell way" <advertise>you can also have a look at Curry</advertise>. Curry is a lazy functional logic programming language that has a Haskell like syntax (http://www.curry-language.org/ ). Besides standard functional features it provides non-determinism and narrowing. In contrast to Haskell overlapping rules in function definitions induce non-determinism. For example the following "function" non-deterministically inserts an element at each position of a list. insert :: a -> [a] -> [a] insert x xs = x : xs insert x (y:ys) = y : insert x ys From the side-effects point of view Curry is very boring as it does not provide type classes but there is one monad namely the IO monad for doing side effects. Cheers, Jan

On Tue, 26 May 2009, Jan Christiansen wrote:
Hi,
On 26.05.2009, at 21:24, Lauri Alanko wrote:
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.
I have to admit that I am not very familiar with Mercury. But if you are looking for "doing Prolog the Haskell way" <advertise>you can also have a look at Curry</advertise>. Curry is a lazy functional logic programming language that has a Haskell like syntax (http://www.curry-language.org/).
You forgot to mention, that you will give a talk about Curry soon, where Matthias might want to attend: http://iba-cg.de/hal4.html :-)

Henning Thielemann wrote:
On Tue, 26 May 2009, Jan Christiansen wrote:
Hi,
On 26.05.2009, at 21:24, Lauri Alanko wrote:
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.
I have to admit that I am not very familiar with Mercury. But if you are looking for "doing Prolog the Haskell way" <advertise>you can also have a look at Curry</advertise>. Curry is a lazy functional logic programming language that has a Haskell like syntax (http://www.curry-language.org/).
You forgot to mention, that you will give a talk about Curry soon, where Matthias might want to attend: http://iba-cg.de/hal4.html
:-)
By the way, did Curry solved the problem of how to deal with IO and backtracking issues? (where and where not should IO happen kind of a thing) I haven't used Curry that much but I remember that there was an issue of IO and non-determinism.

On May 27, 2009, at 1:01 AM, Ahn, Ki Yung wrote:
By the way, did Curry solved the problem of how to deal with IO and backtracking issues? (where and where not should IO happen kind of a thing)
Curry uses the IO monad to specify where IO actions may happen. Non- determinism is not excluded statically from IO actions but usually leads to a run-time error (see Section 7.1 of [1]). For example the Curry systems PAKCS [2] and MCC [3] show the following behaviour (the infix operator (?) denotes non-deterministic choice): $ pakcs Prelude> print (1?2) 1 2 ERROR: non-determinism in I/O actions occurred! Prelude> :q $ cyi Prelude> print (1?2) Error: cannot duplicate the world Prelude> :q In order to use non-deterministic operations in an IO context, their results need to be *encapsulated*, i.e., collected in a data structure (e.g. a list). See [4,5] for recent research on encapsulated search. The Curry System KiCS [6] uses encapsulated search implicitly in IO operations and uses the first result if there is one and only yields an error otherwise: $ kicsi Prelude> print (1?2) 1 Prelude> print (1=:=2) non-exhaustive patterns in function Prelude._case_1 <interactive>: program error Prelude> :q Cheers, Sebastian [1]: http://www.informatik.uni-kiel.de/~curry/report.html [2]: http://www.informatik.uni-kiel.de/~pakcs/ [3]: http://danae.uni-muenster.de/~lux/curry/ [4]: http://www.informatik.uni-kiel.de/~mh/papers/JFLP04_findall.html [5]: Computing with subspaces, http://web.cecs.pdx.edu/~antoy/homepage/publications.html [6]: http://www.informatik.uni-kiel.de/prog/mitarbeiter/bernd-brassel/projects/ -- Underestimating the novelty of the future is a time-honored tradition. (D.G.)

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.
I have to admit that I am not very familiar with Mercury. But if you are looking for "doing Prolog the Haskell way" <advertise>you can also have a look at Curry</advertise>. Curry is a lazy functional logic programming language that has a Haskell like syntax (http://www.curry-language.org/).
You forgot to mention, that you will give a talk about Curry soon, where Matthias might want to attend: http://iba-cg.de/hal4.html
Indeed. Studying in Magdeburg, I already heard about that workshop and considered attending, but I did not read the agenda in detail. Now I'll definitely attend.
participants (6)
-
Ahn, Ki Yung
-
Henning Thielemann
-
Jan Christiansen
-
Lauri Alanko
-
Matthias Görgens
-
Sebastian Fischer