Haskell vs. Prolog comparison [closed] - haskell

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.

Related

Are there other HOL programming languages besides Caledon that are based on haskell?

There are programming languages and theorem prover based on higher order logic (HOL). Examples include Twelf, lambda prolog, Isabelle. For example Twelf is is both a programming language and a theorem prover, while Isabelle is mainly a theorem prover, but for Isabelle code extraction is available.
I am looking for a HOL programming language based on haskell. The reason is that I like, for instance, lambda prolog very much, but it is not meant as a practical programming language. Lambda prolog lacks a standard library and interfacing with external libraries doesn't seem trivial. The problem is if you need some functionality, like writing a parser for a text file, you can't interface, say, with the many available existing libraries for haskell, and further, there is no standard library so you start from scratch.
Today I came across the Caledon programming language that was implemented as a master thesis, it seems. From the github page:
Caledon is a dependently typed, polymorphic, higher order logic
programming language.
This is interesting, since it is written in haskell so it should be easy to extend and interface with existing haskell libraries. But it seems that the project is in a bit early stage, I am not sure if input-output (IO) is implemented. Since I learned only today about Caledon, I think I might have missed some further projects. (BTW, I am not interested in standard logic programming languages like prolog).
Are there programming languages based on higher order logic besides Caledon that are implemented in haskell?
(I am asking for "implemented in haskell", as it is rather easy to connect programming languages that can be extracted to or are implemented in haskell. For example the Agda programming language can compile to haskell code and haskell libraries can be used conveniently and is extremly easy to use haskell libraries if you know how. Many other programming languages (e.g., ATS) I belive only provide the smallest common denominator which is a C based foreign function interface (FFI). In my eyes it is quite cumbersome to connect two higher programming languages via their respective C-based FFI interface. Thus the seemly abitrary part that "it should be implemented in haskell". Further, as a side note some users have downvoted in the past for my description of Agda as a programming language, but of course this is not true, i.e., consider Curry-Howard )
"Haskabelle is a converter from Haskell source files to Isabelle/HOL theories implemented in Haskell itself."
Haskabelle
Strange Statement: Haskell' is a higher order logic programming language based on Haskell. Type inference in Haskell with multiparameter type classes, type families, undecidable inference and whatnot actually forms a higher order logic programming language. This probably doesn't help you very much because:
The spec is literally constantly changing (I've had a few packages loose compatibility as they were based on hacks that got "fixed")
The type system itself doesn't have IO (yet?)
It can't really call other Haskell libraries from type inference
Its not very fast.
The logic programming semantics aren't exactly clear or stable.
It doesn't permit you to unify with lambdas or other type classes, although it does permit unification with functions.
Sadly, I know of extraordinarily few full HOL languages let alone ones implemented in Haskell - it turns out higher order unification is a huge pain to implement.
short answer: i don't know. long answer: you have small chances you will find purely academic language with thousands of libraries and tools for it. if you for some reason need that specific language for some specific problem then use it ONLY for that problem. not for parsing files, calculating taxes or launching rockets. create library and link it with other programs. or even better: create a microservice or connect the programs in other way (e.g. standard input/output) that doesn't require much effort. always use best tool for the job

How are J/K/APL classified in terms of common paradigms?

I've just started learning J, which is very interesting, but I was wondering what kind of language it is exactly, in relation to common paradigms and classifications. For example, you could say that F# is a strongly typed, mainly functional (it supports OO and procedural programming, but it's considered to be "functional") language which belongs to the ML family. For J, however, I couldn't find much on how to classify it "conventionally", or find anything on Stackoverflow confirming that it's a functional programming language. Wikipedia says that it "is a very terse array programming language", "supports function-level programming", and "is not a Von Neumann programming language", none of which are more helpful.
I have a couple of questions:
What main paradigm (procedural, OO, functional, logical) do J/K/APL fall under? If their paradigm is only "array programming", what paradigm does that fall under or is most similar to?
What well-known programming languages are J/K/APL most similar to? For example, I'd guess that they're like Lisp, since they operate on arrays (lists) and have minimal, no comma syntax.
I'm just trying to categorize these languages in my head according to what I already know. Thank you.
J is related to the kind of functional programming (sometimes known as function-level programming, as opposed to value-level) advocated by John Backus, who is probably better known as the inventor of Fortran but spent the latter part of his career trying to move programming away from the style used by Fortran.
In his Turing Award Lecture entitled "Can Programming be Liberated from the von Neumann Style?" Backus presented an overview of his ideas, which he experimented with in his FP and FL languages. Those were inspired largely by Ken Iverson's APL, and Iverson in turn borrowed from Backus' languages when he developed J.
The key idea behind these, which was expanded and developed as a paradigm as the language family grew, was the formation of an algebra of programming. Using these algebraic tools, a programmer could derive or calculate a correct program to solve a problem by combining standard higher-order functions according to well-known mathematical rules. From the abstract of the lecture above:
Associated with the functional style of programming is an algebra of
programs whose variables range over programs and whose operations are
combining forms. This algebra can be used to transform programs and to
solve equations whose "unknowns" are programs in much the same way one
transforms equations in high school algebra. These transformations are
given by algebraic laws and are carried out in the same language in
which programs are written. Combining forms are chosen not only for
their programming power but also for the power of their associated
algebraic laws. General theorems of the algebra give the detailed
behavior and termination conditions for large classes of programs.
Although there doesn't seem to be a lot of recent research that uses the notation of this family of languages, the key ideas have seen somewhat recent development in other functional languages. Richard Bird and Lambert Meertens worked on a related formalism for algebraic manipulation and derivation of programs and the data they operate on; this is known as the Bird-Meertens Formalism or, informally, Squiggol.
Bird and Philip Wadler later wrote a text, "Introduction to Functional Programming", which introduced students to the more well-known "value-level" functional programming based on the lambda calculus. It originally used the Miranda programming language, a forerunner to Haskell, but in its 2nd edition was translated to use Haskell. I mention this because Erik Meijer, Maarten Fokkinga, and Ross Paterson used the example functions in the text as the motivating examples in their well-known paper "Functional Programming with Bananas, Lenses, Envelopes, and Barbed Wire", where they extend the Bird-Meertens Formalism, give it a basis in Category Theory, and show how the solution to each of the examples can be calculated based on the laws of the formalism and the recursion schemes captured by its higher-order functions.
These ideas took root in Haskell, and there you can find a style of programming known as "point-free" that bears a strong resemblance to FP programming. It eschews named variables and creates a new function purely by composition of other functions. Most of the language is not optimized for this use, so many functions are awkward to create in point-free style using only the standard libraries, but alternate libraries that provide more Squiggol-style combinator functions are available.
The algebraic style of constructing programs, thanks to its mathematical nature, is amenable to high-level analysis and transformation by sophisticated compilers. This has led to developments in "Fusion" or "Deforestation" optimizations in functional language compilers that allow algorithms expressed in this style to be reduced to highly efficient machine code loops without all the garbage data and redundant loops that a more naive translation would require. Earlier this year, a framework for generalized stream fusion was presented that showed very practical results from this style of programming.
Hopefully this background gives you a better idea of what the Wikipedia article was talking about and how the underlying paradigm works.
While other tags could also apply (as with other languages), J is certainly a functional language. It has most major attributes attributed to functional languages, such as functions being 'first class citizens,' currying, higher order functions, etc. Furthermore, if it means anything to you, I have read articles where the language creators themselves described the language as 'functional.'
You could also say that it is an array programming language, as all functions operate on arrays vs. single elements.
I think the short answer you are looking for is that J is a functional array programming language. You could also throw other descriptors out there, such as non-statically typed, etc.
As to your numbered questions:
Functional and array programming.
As far as array programming goes, they are not similar to any other well-known language; rather they are in their own category of 'array programming languages.' As far as functional aspects go, they'd be in the functional category.

What language to learn after Haskell? [closed]

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 11 years ago.
Locked. This question and its answers are locked because the question is off-topic but has historical significance. It is not currently accepting new answers or interactions.
As my first programming language, I decided to learn Haskell. I'm an analytic philosophy major, and Haskell allowed me to quickly and correctly create programs of interest, for instance, transducers for natural language parsing, theorem provers, and interpreters. Although I've only been programming for two and a half months, I found Haskell's semantics and syntax much easier to learn than more traditional imperative languages, and feel comfortable (now) with the majority of its constructs.
Programming in Haskell is like sorcery, however, and I would like to broaden my knowledge of programming. I would like to choose a new programming language to learn, but I do not have enough time to pick up an arbitrary language, drop it, and repeat. So I thought I would pose the question here, along with several stipulations about the type of language I am looking for. Some are subjective, some are intended to ease the transition from Haskell.
Strong type system. One of my favorite parts of programming in Haskell is writing type declarations. This helps structure my thoughts about individual functions and their relationship to the program as a whole. It also makes informally reasoning about the correctness of my program easier. I'm concerned with correctness, not efficiency.
Emphasis on recursion rather than iteration. I use iterative constructs in Haskell, but implement them recursively. However, it is much easier to understand the structure of a recursive function than a complicated iterative procedure, especially when using combinators and higher-order functions like maps, folds and bind.
Rewarding to learn. Haskell is a rewarding language to work in. It's a little like reading Kant. My experience several years ago with C, however, was not. I'm not looking for C. The language should enforce a conceptually interesting paradigm, which in my entirely subjective opinion, the C-likes do not.
Weighing the answers: These are just notes, of course. I'd just like to reply to everyone who gave well-formed responses. You have been very helpful.
1) Several responses indicated that a strong, statically typed language emphasizing recursion means another functional language. While I want to continue working strongly with Haskell, camccann and larsmans correctly pointed out that another such language would "ease the transition too much." These comments have been very helpful, because I am not looking to write Haskell in Caml! Of the proof assistants, Coq and Agda both look interesting. In particular, Coq would provide a solid introduction to constructive logic and formal type theory. I've spent a little time with first-order predicate and modal logic (Mendellsohn, Enderton, some of Hinman), so I would probably have a lot of fun with Coq.
2) Others heavily favored Lisp (Common Lisp, Scheme and Clojure). From what I gather, both Common Lisp and Scheme have excellent introductory material (On Lisp and The Reasoned Schemer, SICP). The material in SICP causes me to lean towards Scheme. In particular, Scheme through SICP would cover a different evaluation strategy, the implementation of laziness, and a chance to focus on topics like continuations, interpreters, symbolic computation, and so on. Finally, as others have pointed out, Lisp's treatment of code/data would be entirely new. Hence, I am leaning heavily towards option (2), a Lisp.
3) Third, Prolog. Prolog has a wealth of interesting material, and its primary domain is exactly the one I'm interested in. It has a simple syntax and is easy to read. I can't comment more at the moment, but after reading an overview of Prolog and skimming some introductory material, it ranks with (2). And it seems like Prolog's backtracking is always being hacked into Haskell!
4) Of the mainstream languages, Python looks the most interesting. Tim Yates makes the languages sound very appealing. Apparently, Python is often taught to first-year CS majors; so it's either conceptually rich or easy to learn. I'd have to do more research.
Thank you all for your recommendations! It looks like a Lisp (Scheme, Clojure), Prolog, or a proof assistant like Coq or Agda are the main langauages being recommended.
I would like to broaden my knowledge of programming. (...) I thought I would pose the question here, along with several stipulations about the type of language I am looking for. Some are subjective, some are intended to ease the transition from Haskell.
Strong type system. (...) It also makes informally reasoning about the correctness of my program easier. I'm concerned with correctness, not efficiency.
Emphasis on recursion rather than iteration. (...)
You may be easing the transition a bit too much here, I'm afraid. The very strict type system and purely functional style are characteristic of Haskell and pretty much anything resembling a mainstream programming language will require compromising at least somewhat on one of these. So, with that in mind, here are a few broad suggestions aimed at retaining most of what you seem to like about Haskell, but with some major shift.
Disregard practicality and go for "more Haskell than Haskell": Haskell's type system is full of holes, due to nontermination and other messy compromises. Clean up the mess and add more powerful features and you get languages like Coq and Agda, where a function's type contains a proof of its correctness (you can even read the function arrow -> as logical implication!). These languages have been used for mathematical proofs and for programs with extremely high correctness requirements. Coq is probably the most prominent language of the style, but Agda has a more Haskell-y feel (as well as being written in Haskell itself).
Disregard types, add more magic: If Haskell is sorcery, Lisp is the raw, primal magic of creation. Lisp-family languages (also including Scheme and Clojure) have nearly unparalleled flexibility combined with extreme minimalism. The languages have essentially no syntax, writing code directly in the form of a tree data structure; metaprogramming in a Lisp is easier than non-meta programming in some languages.
Compromise a bit and move closer to the mainstream: Haskell falls into the broad family of languages influenced heavily by ML, any of which you could probably shift to without too much difficulty. Haskell is one of the strictest when it comes to correctness guarantees from types and use of functional style, where others are often either hybrid styles and/or make pragmatic compromises for various reasons. If you want some exposure to OOP and access to lots of mainstream technology platforms, either Scala on the JVM or F# on .NET have a lot in common with Haskell while providing easy interoperability with the Java and .NET platforms. F# is supported directly by Microsoft, but has some annoying limitations compared to Haskell and portability issues on non-Windows platforms. Scala has direct counterparts to more of Haskell's type system and Java's cross-platform potential, but has a more heavyweight syntax and lacks the powerful first-party support that F# enjoys.
Most of those recommendations are also mentioned in other answers, but hopefully my rationale for them offers some enlightenment.
I'm going to be That Guy and suggest that you're asking for the wrong thing.
First you say that you want to broaden your horizons. Then you describe the kind of language that you want, and its horizons sound incredibly like the horizons you already have. You're not going to gain very much by learning the same thing over and over.
I would suggest you learn a Lisp — i.e. Common Lisp, Scheme/Racket or Clojure. They're all dynamically typed by default, but feature some sort of type hinting or optional static typing. Racket and Clojure are probably your best bets.
Clojure is more recent and has more Haskellisms like immutability by default and lots of lazy evaluation, but it's based on the Java Virtual Machine, which means it has some odd warts (e.g. the JVM doesn't support tail call elimination, so recursion is kind of a hack).
Racket is much older, but has picked up a lot of power along the way, such as static type support and a focus on functional programming. I think you'd probably get the most out of Racket.
The macro systems in Lisps are very interesting and vastly more powerful than anything you'll see anywhere else. That alone is worth at least looking at.
From the standpoint of what suits your major, the obvious choice seems like a logic language such as Prolog or its derivatives. Logic programming can be done very neatly in a functional language (see, e.g. The Reasoned Schemer) , but you might enjoy working with the logic paradigm directly.
An interactive theorem proving system such as twelf or coq might also strike your fancy.
I'd advise you learn Coq, which is a powerful proof assistant with syntax that will feel comfortable to the Haskell programmer. The cool thing about Coq is it can be extracted to other functional languages, including Haskell. There is even a package (Meldable-Heap) on Hackage that was written in Coq, had properties proven about its operation, then extracted to Haskell.
Another popular language that offers more power than Haskell is Agda - I don't know Agda beyond knowing it is dependently typed, on Hackage, and well respected by people I respect, but those are good enough reasons to me.
I wouldn't expect either of these to be easy. But if you know Haskell and want to move forward to a language that gives more power than the Haskell type system then they should be considered.
As you didn't mention any restrictions besides your subjective interests and emphasize 'rewarding to learn' (well, ok, I'll ignore the static typing restriction), I would suggest to learn a few languages of different paradigms, and preferably ones which are 'exemplary' for each of them.
A Lisp dialect for the code-as-data/homoiconicity thing and because they are good, if not the best, examples of dynamic (more or less strict) functional programming languages
Prolog as the predominant logic programming language
Smalltalk as the one true OOP language (also interesting because of its usually extremely image-centric approach)
maybe Erlang or Clojure if you are interested in languages forged for concurrent/parallel/distributed programming
Forth for stack oriented programming
(Haskell for strict functional statically typed lazy programming)
Especially Lisps (CL not as much as Scheme) and Prolog (and Haskell) embrace recursion.
Although I am not a guru in any of these languages, I did spend some time with each of them, except Erlang and Forth, and they all gave me eye-opening and interesting learning experiences, as each one approaches problem solving from a different angle.
So, though it may seem as if I ignored the part about your having no time to try a few languages, I rather think that time spent with any of these will not be wasted, and you should have a look at all of them.
How about a stack-oriented programming language? Cat hits your high points. It is:
Statically typed with type inference.
Makes you re-think common imperative languages concepts like looping. Conditional execution and looping are handled with combinators.
Rewarding - forces you to understand yet another model of computation. Gives you another way to think about and decompose problems.
Dr. Dobbs published a short article about Cat in 2008 though the language has changed slightly.
If you want a strong(er)ly typed Prolog, Mercury is an interesting choice. I've dabbled in it in the past and I liked the different perspective it gave me. It also has moded-ness (which parameters need to be free/fixed) and determinism (how many results are there?) in the type system.
Clean is very similar to Haskell, but has uniqueness typing, which are used as an alternative to Monads (more specifically, the IO monad). Uniqueness typing also does interesting stuff to working with arrays.
I'm a bit late but I see that no one has mentioned a couple of paradigms and related languages that can interest you for their high-level of abstraction and generality:
rewriting systems, like Maude or ELAN;
Constraint Handling Rules (CHR).
Despite its failure to meet one of your big criteria (static* typing), I'm going to make a case for Python. Here are a few reasons I think you should take a look at it:
For an imperative language, it is surprisingly functional. This was one of the things that struck me when I learned it. Take list comprehensions, for example. It has lambdas, first-class functions, and many functionally-inspired compositions on iterators (maps, folds, zips...). It gives you the option of picking whatever paradigm suits the problem best.
IMHO, it is, like Haskell, beautiful to code in. The syntax is simple and elegant.
It has a culture that focuses on doing things in a straightforward way, rather than focusing too minutely on efficiency.
I understand if you are looking for something else though. Logic programming, for instance, might be right up your alley, as others have suggested.
* I assume you mean static typing here, since you want to declare the types. Techincally, Python is a strongly typed language, since you can't arbitrarily interpret, say, a string as an number. Interestingly, there are Python derivatives that allow static typing, like Boo.
I would recommend you Erlang. It is not strong typed language and you should try it. It is very different approach to programming and you may find that there are problems where strong typing is not The Best Tool(TM). Anyway Erlang provides you tools for static type verification (typer, dialyzer) and you can use strong typing on parts where you gain benefits from it. It can be interesting experience for you but be prepared, it will be very different feeling. If you are looking for "conceptually interesting paradigm" you can found them in Erlang, message passing, memory separation instead sharing, distribution, OTP, error handling and error propagation instead of error "prevention" and so. Erlang can be far away from your current experience but still brain tickling if you have experience with C and Haskell.
Given your description, I would suggest Ocaml or F#.
The ML family are generally very good in terms of a strong type system. The emphasis on recursion, coupled with pattern matching, is also clear.
Where I am a bit hesitant is on the rewarding to learn part. Learning them was rewarding for me, no doubt. But given your restrictions and your description of what you want, it seems you are not actually looking for something much more different than Haskell.
If you didn't put your restrictions I would have suggested Python or Erlang, both of which would take you out of your comfort zone.
In my experience, strong typing + emphasis on recursion means another functional programming language. Then again, I wonder if that's very rewarding, given that none of them will be as "pure" as Haskell.
As other posters have suggested, Prolog and Lisp/Scheme are nice, even though both are dynamically typed. Many great books with a strong theoretical "taste" to them have been published about Scheme in particular. Take a look at SICP, which also conveys a lot of general computer science wisdom (meta-circular interpreters and the like).
Factor will be a good choice.
You could start looking into Lisp.
Prolog is a cool language too.
If you decide to stray from your preference for a type system,you might be interested in the J programming language. It is outstanding for how it emphasizes function composition. If you like point-free style in Haskell, the tacit form of J will be rewarding. I've found it extraordinarily thought-provoking, especially with regard to semantics.
True, it doesn't fit your preconceptions as to what you'd like, but give it a look. Just knowing that it's out there is worth discovering. The sole source of complete implementations is J Software, jsoftware.com.
Go with one of the main streams. Given the resources available, future marketability of your skill, rich developer ecosystem I think you should start with either Java or C#.
Great question-- I've been asking it myself recently after spending several months thoroughly enjoying Haskell, although my background is very different (organic chemistry).
Like you, C and its ilk are out of the question.
I've been oscillating between Python and Ruby as the two practical workhorse scripting languages today (mules?) that both have some functional components to them to keep me happy. Without starting any Rubyist/Pythonist debates here, but my personal pragmatic answer to this question is:
Learn the one (Python or Ruby) that you first get an excuse to apply.

What are the pros and cons of Haskell? [closed]

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 9 years ago.
Improve this question
I've learned several languages, but now I want to choose one. The language that I most liked was Haskell, which is like an interpreted language but is a compiled.
What are the pros and cons of Haskell?
Just a couple of ideas I've got in my head at the moment.
Pros
Learning Haskell will change the way you think about programming. (People often find themselves writing Haskell-like code in other languages once they learn Haskell.)
Type safety is miles above mainstream languages (null pointer exceptions, anyone?)
Type inference means you don't have to worry about types, unless absolutely necessary.
It produces high performant executables.
Parallelism is almost trivial with the par and pseq combinators
The interactive environment (hugs/ghci) allow you to prototype ideas quickly
Has a nice supportive community (IRC, mailing lists, etc.)
Very expressive and concise syntax
GHC is actively being developed and improved, including support for code execution on GPU for that extra kick of high-performance computing
QuickCheck > unit testing
Cons
Learning Haskell will ruin all other languages for you.
It's quite complicated to get into
Very easy to write cryptic programs that no-one understands, not even yourself a few days later
There are cons to using Haskell for certain projects, but there are no cons to learning Haskell. It takes time, but it is worth it. You will be a better programmer.
I would also like to stress some of the practical features of Haskell, despite its mere beauty:
Gets in your way exactly where it should, and keeps out of your way otherwise. That's one of the interesting features, which is responsible for why Haskell just works.
Has a great concurrency system, which is ready for high performance applications.
Provides the basis for new, innovative abstractions and design patterns, among them my personal favorite, functional reactive programming.
Makes even very complicated problems easy to tackle, because a lot of the things, which you need to think about in other languages (proper sequencing, locking, initialization, etc.), are much less of an issue in Haskell.
Laziness is not simply an optimization. It allows you to solve problems in entirely new ways, which are much easier on the brain. No destructive updates, yet the same result with about the same performance.
If you have the choice, I totally recommend learning Haskell over any other language. It seems to make the optimal tradeoff between safety, level of abstractness and practicality among the existing languages.
Pros:
1) Haskell is the most state-of-the-art programming language.
I did some research and haskell seems to be the only real state-of-the-art programming language. There are others like agda and coq, but those are quite experimental and lack features for real world programming (e.g. library support). It’s best to invest in a state-of-the art programming language.
(note: I don't argue about the details why haskell is state-of-the-art, and almost any other programming language is not. This would take too much time. So it's simply my subjective opinion. Same is true for the other statements.)
(note: some features I mention later are probably GHC specific, but I still write only haskell)
2) Haskell programmers are typically very smart. The code quality of the libraries is exceptionally high. Further, tips on stackoverflow are very well written, and also on a high level (thanks to people like Don Stewart, just to name one). I think one of the best ways to improve in programming is by learning from other peoples' code. Haskell is very good in that regard.
3) Imperative programming in moste OOP languages is obsolete. So is usual way of programming with side effects. But there are very few programming languages for declarative programming without side-effects. For instance Scala, F#, Ocaml and Erlang are not side effect free. (However, there is work, also in the academic field on OOP languages that are clearly not obsolete. Consider the work of Alan Kay in the past or for instance current state-of-the art academic work in the realm of Smalltalk.)
4) Haskell supports programming with abstract mathematical concepts (e.g. monads, functors, combinators, GADT, etc.). I think this boosts programming productivity.
5) The Haskell type system is very flexible, and supports type inference. This reduces the possible errors a lot. The type system is checked at compile time. The type systems helps as documentation.
6) Some state-of-the art concepts are implemented in haskell first (like the QuickCheck library). There are a lot of interesting extensions.
7) The haskell syntax is very well designed. There are no unnecessary parenthesis. The code is compact and the synatax for pattern matching and list comprehension is quite nice. People like Knuth advocate literate programming, and haskell/GHC supports it.
8) haskell supports lazy evaluation
Cons:
1) It's very hard to learn, and it takes hours, months to master haskell. It’s even harder without a proper computer science background. Things like Monads and Functors are hard to understand, especially without mathematical background. So most programmers probably don’t have the ability or will to learn haskell. Haskell is not ‘simple’. Howevery it’s impossible to have a simple language that supports all the advanced features.
2) The IDE options are not as good as those for other programming languages. I use leksah as my IDE, it’s very good, but it’s not comparable to Eclipse for java development.
3) Haskell cannot be used for android or Iphone development. In contrast Scala can be used for android development, and it’s also compatible to java, which is a huge advantage.
4) I think some libraries lack supporting people who maintain and improve them. I do semantic web programming in haskell, and the library support could be better.
Haskell is not suited for all projects. If you need every millisecond of performance, C/C++ is still probably the best option. So haskell is suited for many projects, but not all.
Haskell has many technical advantages over other programming languages. However, there might be political reason against using haskell. For example Scala integrates better with existing java infrastructure.
What do you want to write, what type of applications? What problems do you want to solve?
There are some problem types that Haskell will excel in, but, if you write a program that requires constantly changing state then Haskell is a bad choice.
If while modeling the problem it doesn't fit well with functional programming, such as writing a CAD (computer-aided design) program, OOP would be a better choice, just because the programming paradigm fits better with the model.
But, if you are not affected by these problems then Haskell can be a great language to use.
but now I want to choose one
...
Then I want to know the pros and cons of this powerfull language(just to make the correct choice).
If you will permit me to generalize, the choice of a language really depends on the problem you are trying to solve. There is no one choice that will work for everything, and
there will always be some language that will look better than the one you are using now.
Keep learning new languages, however, since the experiences will heighten your abilities to know when a language is wrong for a project.

What is Haskell used for in the real world? [closed]

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 9 years ago.
Improve this question
There is a lot of hype around Haskell, however, it is hard to get information on how it is used in the real world applications. What are the most popular projects / usages of Haskell and why it excels at solving these problems?
What are some common uses for this
language?
Rapid application development.
If you want to know "why Haskell?", then you need to consider advantages of functional programming languages (taken from https://c2.com/cgi/wiki?AdvantagesOfFunctionalProgramming):
Functional programs tend to be much more terse than their ImperativeLanguage counterparts. Often this leads to enhanced
programmer productivity
FP encourages quick prototyping. As such, I think it is the best software design paradigm for ExtremeProgrammers... but what do I know?
FP is modular in the dimension of functionality, where ObjectOrientedProgramming is modular in the dimension of different
components.
The ability to have your cake and eat it. Imagine you have a complex OO system processing messages - every component might make state
changes depending on the message and then forward the message to some
objects it has links to. Wouldn't it be just too cool to be able to
easily roll back every change if some object deep in the call
hierarchy decided the message is flawed? How about having a history of
different states?
Many housekeeping tasks made for you: deconstructing data structures (PatternMatching), storing variable bindings (LexicalScope with
closures), strong typing (TypeInference), GarbageCollection, storage
allocation, whether to use boxed (pointer-to-value) or unboxed (value
directly) representation...
Safe multithreading! Immutable data structures are not subject to data race conditions, and consequently don't have to be protected by
locks. If you are always allocating new objects, rather than
destructively manipulating existing ones, the locking can be hidden in
the allocation and GarbageCollection system.
Apart from this Haskell has its own advantages such as:
Clear, intuitive syntax inspired by mathematical notation.
List comprehensions to create a list based on existing lists.
Lambda expressions: create functions without giving them explicit names. So it's easier to handle big formulas.
Haskell is completely referentially transparent. Any code that uses I/O must be marked as such. This way, it encourages you to separate code with side effects (e.g. putting text on the screen) from code without (calculations).
Lazy evaluation is a really nice feature:
Even if something would usually cause an error, it will still work as long as you don't use the result. For example, you could put 1 / 0 as the first item of a list and it will still work if you only used the second item.
It is easier to write search programs such as this sudoku solver because it doesn't load every combination at once—it just generates them as it goes along. You can do this in other languages, but only Haskell does this by default.
You can check out following links:
https://c2.com/cgi/wiki?AdvantagesOfFunctionalProgramming
https://learn.microsoft.com/archive/blogs/wesdyer/why-functional-programming-is-important-in-a-mixed-environment
https://web.archive.org/web/20160626145828/http://blog.kickino.org/archives/2007/05/22/T22_34_16/
https://useless-factor.blogspot.com/2007/05/advantage-of-functional-programming.html
I think people in this post are missing the most important point for anyone who has never used a functional programming language: expanding your mind. If you are new to functional programming then Haskell will make you think in ways you've never thought before. As a result your programming in other areas and other languages will improve. How much? Hard to quantify.
There is one good answer for what a general purpose language like Haskell is good for: writing programs in general.
For what it is used for in practice, I've three approaches to establishing that:
A tag cloud of Haskell library and app areas, weighted by frequency on Hackage.
Indicates that it is good for graphics, networking, systems programming, data structures, databases, development, text processing ...
Areas it is used in industry - a lot of DSLs, web apps, compiler design, networking, analysis, systems programming , ...
And finally, my opinion on what it is really strong at:
Problems where correctness matters, domain specific languages, and parallel and concurrent programming
I hope that gives you a sense on how broad your question is, if it is to be answered with any specificity.
One example of Haskell in action is xmonad, a "featureful window manager in less than 1200 lines of code".
From the Haskell Wiki:
Haskell has a diverse range of use
commercially, from aerospace and
defense, to finance, to web startups,
hardware design firms and lawnmower
manufacturers. This page collects
resources on the industrial use of
Haskell.
According to Wikipedia, the Haskell language was created out of the need to consolidate existing functional languages into a common one which could be used for future research in functional-language design.
It is apparent based on the information available that it has outgrown it's original purpose and is used for much more than research. It is now considered a general purpose functional programming language.
If you're still asking yourself, "Why should I use it?", then read the Why use it? section of the Haskell Wiki Introduction.
Haskell is a general purpose programming language. It can be used for anything you use any other language to do. You aren't limited by anything but your own imagination. As for what it's suited for? Well, pretty much everything. There are few tasks in which a functional language does not excel.
And yes, I'm the Rayne from Dreamincode. :)
I would also like to mention that, in case you haven't read the Wikipedia page, functional programming is a paradigm like Object Oriented programming is a paradigm. Just in case you didn't know. Haskell is also functional in the sense that it works; it works quite well at that.
Just because a language isn't an Object Oriented language doesn't mean the language is limited by anything. Haskell is a general-purpose programming language, and is just as general purpose as Java.
I have a cool one, facebook created a automated tool for rewriting PHP code. They parse the source into an abstract syntax tree, do some transformations:
if ($f == false) -> if (false == $f)
I don't know why, but that seems to be their particular style and then they pretty print it.
https://github.com/facebook/lex-pass
We use haskell for making small domain specific languages. Huge amounts of data processing. Web development. Web spiders. Testing applications. Writing system administration scripts. Backend scripts, which communicate with other parties. Monitoring scripts (we have a DSL which works nicely together with munin, makes it much easier to write correct monitor code for your applications.)
All kind of stuff actually. It is just a everyday general purpose language with some very powerful and useful features, if you are somewhat mathematically inclined.
From Haskell:
Haskell is a standardized, general-purpose purely functional
programming language, with
non-strict semantics and strong static
typing. It is named after logician
Haskell Curry.
Basically Haskell can be used to create pretty much anything you would normally create using other general-purpose languages (e.g. C#, Java, C, C++, etc.).
For example, for developing interactive, realtime HTML5 web applications. See Elm, the compiler of which is implemented in Haskell and the syntax of which borrows a lot from Haskell's.
This is a pretty good source for info about Haskell and its uses:
Open Source Haskell Releases and Growth

Resources