Haskell vs. Prolog comparison

HaskellProlog

Haskell Problem Overview


What kind of problems is better solved in Prolog than in Haskell? What are the main differences between these two languages?


Edit

Is there a Haskell library (kind of a logical solver) that can mimic Prolog functionality?

Haskell Solutions


Solution 1 - Haskell

Regarding the logic library question: If it doesn't exist, it should be possible to build one a variety of ways. The Reasoned Schemer builds logical reasoning capabilities into Scheme. Chapters 33-34 of PLAI discuss Prolog and implementing Prolog. These authors are building bridges between Scheme and Prolog. The creators of PLT Scheme have built as one of their languages a Lazy Scheme after the lazy evaluation feature of Haskell. Oleg Kiselyov's LogicT paper is brilliant as usual--he pushes the boundary for what is possible in many languages. There is also a logic programming example on the Haskell Wiki.

Solution 2 - Haskell

Prolog is mainly a language targeted at logical problems, especially from the AI and linguistic fields. Haskell is more of a general-purpose language.

Prolog is declarative (logical) language, what makes it easier to state logical problems in it. Haskell is a functional language and hence much better suited to computational problems.

Wikipedia on declarative programming:

> In computer science, declarative > programming is a programming paradigm > that expresses the logic of a > computation without describing its > control flow. It attempts to minimize > or eliminate side effects by > describing what the program should > accomplish, rather than describing how > to go about accomplishing it. This is > in contrast from imperative > programming, which requires a detailed > description of the algorithm to be > run. > > Declarative programming consider > programs as theories of a formal > logic, and computations as deductions > in that logic space. Declarative > programming has become of particular > interest recently, as it may greatly > simplify writing parallel programs.

Wikipedia on functional programming:

> In computer science, functional > programming is a programming paradigm > that treats computation as the > evaluation of mathematical functions > and avoids state and mutable data. It > emphasizes the application of > functions, in contrast to the > imperative programming style, which > emphasizes changes in state. > Functional programming has its roots > in the lambda calculus, a formal > system developed in the 1930s to > investigate function definition, > function application, and recursion. > Many functional programming languages > can be viewed as embellishments to the > lambda calculus.

In short a declarative language declares a set of rules about what outputs should result from which inputs and uses those rules to deduce an output from an input, while a functional language declares a set of mathematical or logical functions which define how input is translated to output.


As for the ADDED question : none that I know of but you can either translate Haskell to Prolog, or implement Prolog in Haskell :)

Solution 3 - Haskell

Prolog is a logic programming language, whereas Haskell is a functional language. Functional languages are based on the concept of a function which takes a number of arguments and computes a value.

Prolog, on the other hand, does not have functions. Instead, predicates are used to prove a "theorem". Prolog predicates do not compute a value, they can answer "yes" or "no" and optionally bind input variables to values:

The usefulness of functional and logic programming often overlap. Functional programming has gained quite a bit of traction lately, while Prolog is still much a niche language, much due to the fact that it is much more different from the common concepts of functions and methods of mainstream OOP than functional programming is, and often considered (very) difficult to learn.

Certain problems become almost trivial to implement in Prolog, especially in combination with constraint solvers.

You can read more about logic programming on Wikipedia.

Solution 4 - Haskell

You might find the paper Escape from Zurg: An Exercise in Logic Programming an interesting read. It shows a side-by-side comparison of the implementation of a simple search problem in Prolog and Haskell, along with a little typeclass framework for representing search problems more generally. The conclusion that the authors come to is that expressing at least some of these types of problems in Haskell is easier than in Prolog, primarily because the Haskell type system makes it easier to come up with nice representations of search states and moves from state to state.

Solution 5 - Haskell

In reality there are only 2 languages:

  1. Machine language
  2. Human language.

All other languages in between are merely translators and nothing more. When we use the machine language we must think like the machine and when using human languages we think like humans.

The true job of a programmer is to think both ways. Some programming tools like the assembler force the programmer to spend a lot more time thinking like the machine. Other tools like Prolog allows us to spend more time thinking like a human.

There is a penalty to be paid at each extreme either in performance or in cost.

If the business logic of your application can be reduced to a set of rules and its output to a set of goals (for example writing a game of Chess) then Prolog is ideal. On the other hand if you need to take the input and tell the computer how to compute the output then a functional language would be more appropriate.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestiondanatelView Question on Stackoverflow
Solution 1 - HaskellgknauthView Answer on Stackoverflow
Solution 2 - HaskellKornel KisielewiczView Answer on Stackoverflow
Solution 3 - HaskellJesperEView Answer on Stackoverflow
Solution 4 - HaskellIan RossView Answer on Stackoverflow
Solution 5 - HaskellSquare Rig MasterView Answer on Stackoverflow