When my friend started learning Prolog in school, I made fun of him for learning a useless language. However, he's showed me some stuff I never even knew possible; I want to know where this technique comes from.
The technique is this:
permutation(List) :-
isAMember(X, List),
deleteFirstElement(X, List, Substring),
% and so on
In this code, isAMember(X, List)
is a function that returns true if X
is in List
. However, up to this point X
is not defined as a variable - so the program will spawn a bunch of new threads, one for each possible value of X
that makes isAMember(X, List)
true, and continue from there.
This allows us to create a multi-threaded algorithm in the simplest, most elegant way I could have ever imagined possible.
So my question is: Is this Prolog-specific, or a feature of all logical- and/or functional-languages? Also, where can I learn more amazing multithreading techniques like this - this is surely the future of programming.
The subset of Prolog known as "Datalog" is restricted to pure logical features (no "cut"), and in principle, the proof search could be done in parallel. However you'd have to be careful because the semantics of full Prolog is quite sensitive to the order in which results are produced, and some real Prolog programs depend on this.
The situation in pure functional languages like Haskell and Clean is a bit better—it is always safe to evaluate subexpressions in parallel—but there are many challenges of performance. If you do extreme parallelism (every subexpression) you don't get any performance gains because of all the overhead. The promising approaches at the moment seem to be
Threads (Concurrent Haskell)
Data Parallel Haskell
"Sparks" with par
and seq
operators.
The parallel functional stuff has been around for almost 30 years and people are still trying to make it perform well. If you want more information, try
Recent proceedings of the ACM Symposium on Haskell (and before that, the Haskell workshop)
The work of Arvind at MIT, who was a great pioneer in this area (check out his book with R. Nikhil on parallel programming with pH)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With