What is Haskell used for in the real world?
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.
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.
- 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
You can check out following links:
- https://c2.com/cgi/wiki?AdvantagesOfFunctionalProgramming
- https://docs.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