I am aware that Constraint programming and Logic programming are sub-paradigms of Declarative programming. But I couldn't find a difference between them. What is the difference between them? Could you please provide some examples?
Related
Currently I'm writing a theses for software project, Which uses structural programming techniques. DFD,Context diagrams may helps to depict the software, is there any other diagrams could help to describe the software?
This isn't a programming related question but Structure Charts are probably your best bet.
http://en.wikipedia.org/wiki/Structure_chart
This may also be of interest:
http://en.wikipedia.org/wiki/Jackson_structured_programming
I am very sorry if I ask a wrong question but I really need a professional help. I have to make a rather complex project for a begginer, using Visual Haskell, for a course of functional programming. The problem is that because I am at the beginning I don't know what kind of theme to pick. I want to make a project that evidentiates the real utility of functional programming. If you could just give me some ideas I will be very grateful.
Thanks
You could design a simple programming language and write an interpreter for it:
Check the tools Alex (http://www.haskell.org/alex/) for lexical analysis, and happy (http://www.haskell.org/happy/) for parsing your code.
You can make the language as complex as you want. I think that defining While loops and functions could make it sufficiently complex and satisfying for a beginner.
want to make a project that
evidentiates the real utility of
functional programming. If you could
just give me some ideas I will be very
grateful.
Alright, then let me tell you something. Programming is about expression. Functional languages let you express things differently. What are the benefits of the expressions made possible with functional programming?
Infinite lists and recursion can be expressed very simple.
Recursion is functional programming done right.
Try to implement algorithms and datastructures that use it. Balanced trees, fibonacci, euclidian algorithm, all that will benefit from it. Really, anything that features a tree can be expressed very elegantly in functional languages.
Give mathetmical problems a try, try to solve the Euler Problems with Haskell.
So I guess most (all?) programmers start out learning a mainly imperative/ procedural programming paradigm, and probably learnt some form of object-oriented programming fairly shortly after that. I've read plenty of questions on stackoverflow suggesting functional programming is increasingly important for improved concurrency/ parallelism. Also that programmers should learn many paradigms to improve their skills and broaden their perspectives.
What are some other paradigms (and languages that use it) that are really beneficial to development skills?
There's possibly an argument for looking at a logic language such as Prolog. Other than that, within the universe of functional programming languages there are many varieties (e.g. contrast Haskell, ML, Scala and Scheme). You might want to explore the various dimensions in terms of things like type systems, laziness and syntax.
In formal specifications based on abstract algebraic types and equational theory you use formulas of equational theory to specify theory. System which will satisfy those constraints is called in formal logic a model.
Modeling is process of creating a model, which abstracts of some aspects, which are unnecessary details for a specific case. So concrete system has to adhere to created model in observed aspects.
Programming is a process of creating a program which will have specific behaviour - will perform specific algorithms - and programming languages through different paradigms enable us to think in a certain specific way, which abstracts of some details, usually machine specific ones.
So could we be doing all those things at the same time, because they are principially the same? Is declarative programming the nearest attempt to do that? Could we use some sort f programming languages which will be good for programming as well as for modeling and specification?
The scientist who has done the most to advance this point of view is Tony Hoare. Tony, along with his colleague Edsger Dijkstra, advocated nondeterministic programming languages so that there would be a smoother path from specification to implementation. Tony definitely wanted a single language for both specification and implementation. For more on this view, read his book on the Alegbra of Programming. Tony also did the seminal work on proving correctness of abstractions. All of this work was done in the context of simple, imperative languages with structured control flow and classic, side-effecting procedures. So there is not any connection with declarative programming of necessity. And historically, work on functional programming (the main branch of declarative programming) has followed more from Backus's Turing lecture on "liberating programming from the von Neumann bottleneck"; functional programming has been about programming productivity as much as anything else.
What we discovered since Hoare is that formal specifications and formal modelsl are very expensive. The expense hasn't been shown to be justified except in very special circumstances, like "if the software doesn't work, the patient will die" or "if the software doesn't work, the plane will crash." Informal models and specifications are quite useful, and much cheaper to produce and work with. There is still interesting research going on around the fringes on modelling, model checking, and so on. One of my personal favorites is the Alloy language done by Daniel Jackson's group at MIT. There's also great stuff done at Microsoft Research and plenty of good stuff elsewhere. There's some work in declarative programming as well, but it too is of the "cheap and cheerful" variety rather than a comprehensive, programmatic approach like Hoare's. One of my favorites there is Claessen's and Hughes's QuickCheck, which provides a way to state formal properties and explore them by random testing. No proofs or theorems, but still jolly useful.
In summary, you describe an agenda of doing formal models, specifications, and programs, all within a single framework. There is still plenty of good work going on piecemeal, but the unified agenda has been abandoned.
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 5 years ago.
Improve this question
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?
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.
The Reasoned Schemer by Daniel P. Friedman, William E. Byrd, and Oleg Kiselyov
Programming Languages: Application and Interpretation by Shriram Krishnamurthi
LogicT - backtracking monad transformer with fair operations and pruning
Logic programming on Haskell Wiki
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 :)
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.
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.
In reality there are only 2 languages:
Machine language
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.