Information about Haskell (programming Language)
![]() | |
| Paradigm: | functional, non-strict, modular |
|---|---|
| Appeared in: | 1990 |
| Designed by: | Simon Peyton-Jones, Paul Hudak[1], Philip Wadler, et al |
| Typing discipline: | static, strong, inferred |
| Major implementations: | GHC, Hugs, NHC, JHC, Yhc |
| Dialects: | Helium, Gofer |
| Influenced by: | Miranda, ML |
| Influenced: | Scala |
| Website: | haskell.org |
Haskell is a standardized purely functional programming language with non-strict semantics, named after the logician Haskell Curry.
History
Following the release of Miranda, in 1985, functional languages proliferated. By 1987, there existed more than a dozen non-strict, purely functional programming languages. Of these Miranda was the most widely used, but was proprietary. At the conference on Functional Programming Languages and Computer Architecture (FPCA '87) in Portland, Oregon, a meeting was held during which strong consensus was found among the participants that a committee should be formed to define an open standard for such languages. This would have the express purpose of consolidating the existing languages into a common one that would serve as a basis for future research in language design.[2] The first version of Haskell ("Haskell 1.0") was defined in 1990.[3] The committee's efforts resulted in a series of language definitions, which in late 1997, culminated in Haskell 98, intended to specify a stable, minimal, portable version of the language and an accompanying standard library for teaching, and as a base for future extensions. The committee expressly welcomed the creation of extensions and variants of Haskell 98 via adding and incorporating experimental features.In January 1999, the Haskell 98 language standard was originally published as "The Haskell 98 Report". In January 2003, a revised version was published as "Haskell 98 Language and Libraries: The Revised Report".[4] The language continues to evolve rapidly, with the Hugs and GHC implementation (see below) representing the current de facto standard. In early 2006, the process of defining a successor to the Haskell 98 standard, informally named Haskell′ ("Haskell Prime"), was begun.[5] This process is intended to produce a minor revision of Haskell 98.[6]
Features and extensions
Characteristic features of Haskell include pattern matching, currying, list comprehensions [7], guards, definable operators, and single assignment. The language also supports recursive functions and algebraic data types, as well as lazy evaluation. Unique concepts include monads, and type classes. The combination of such features can make functions which would be difficult to write in a procedural programming language almost trivial to implement in Haskell.Several variants have been developed: parallelizable versions from MIT and Glasgow, both called Parallel Haskell; more parallel and distributed versions called Distributed Haskell (formerly Goffin) and Eden; a speculatively evaluating version called Eager Haskell and several object oriented versions: Haskell++, O'Haskell and Mondrian.
There is also a Haskell-like language that offers a new method of support for GUI development called Concurrent Clean. Its biggest deviations from Haskell are use of uniqueness types for input instead of monads.
Applications
Although Haskell has a comparatively small user community, its strengths have been well applied to a few projects. Audrey Tang's Pugs is an implementation for the long-term forthcoming Perl 6 language with an interpreter and compilers that proved useful already after just a few months of its writing; similarly, GHC is often a testbed for advanced functional programming features and optimizations. Darcs is a revision control system, with several innovative features. Linspire GNU/Linux chose Haskell for system tools development.[8] Xmonad is a window manager for the X Window System, written entirely in Haskell.Examples
A simple example that is often used to demonstrate the syntax of functional languages is the factorial function for positive integers, shown in Haskell:fac :: Integer -> Integer fac 0 = 1 fac n | n > 0 = n * fac (n-1)
Or in one line:
fac n = if n > 0 then n * fac (n-1) else 1
This describes the factorial as a recursive function, with one terminating base case. It is similar to the descriptions of factorials found in mathematics textbooks. Much of Haskell code is similar to standard mathematical notation in facility and syntax.
The first line of the factorial function shown is optional, and describes the types of this function. It can be read as the function fac (fac) has type (::) from integer to integer (Integer -> Integer). That is, it takes an integer as an argument, and returns another integer. The type of a definition is inferred automatically if the programmer didn't supply a type annotation.
The second line relies on pattern matching, an important feature of Haskell. Note that parameters of a function are not in parentheses but separated by spaces. When the function's argument is 0 (zero) it will return the integer 1 (one). For all other cases the third line is tried. This is the recursion, and executes the function again until the base case is reached.
A guard protects the third line from negative numbers for which a factorial is undefined. Without the guard this function would recurse through all negative numbers without ever reaching the base case of 0. As it is, the pattern matching is not complete: if a negative integer is passed to the fac function as an argument, the program will fail with a runtime error. A final case could check for this error condition and print an appropriate error message instead.
The "Prelude" is a number of small functions analogous to C's standard library. Using the Prelude and writing in the point-free style of unspecified arguments, it becomes:
fac = product . enumFromTo 1
The above is close to mathematical definitions such as f = g o h (see function composition) with the dot acting as the function composition operator, and indeed, it is not an assignment of a numeric value to a variable.
In the Hugs interpreter, you often need to define the function and use it on the same line separated by a where or let..in, meaning you need to enter this to test the above examples and see the output 120: let { fac 0 = 1; fac n | n > 0 = n * fac (n-1) } in fac 5 or fac 5 where fac = product . enumFromTo 1
The GHCi interpreter doesn't have this restriction and function definitions can be entered on one line and referenced later.
More complex examples
A simple RPN calculator expressed with the higher-order functionfoldl whose argument f is defined in a where clause using pattern matching and the type class Read:
calc :: String -> [Float]
calc = foldl f [] . words
where
f (x:y:zs) "+" = y+x:zs
f (x:y:zs) "-" = y-x:zs
f (x:y:zs) "*" = y*x:zs
f (x:y:zs) "/" = y/x:zs
f xs y = read y : xs
The empty list is the initial state, and f interprets one word at a time, either matching two numbers from the head of the list and pushing the result back in, or parsing the word as a floating-point number and prepending it to the list.
The following definition produces the list of Fibonacci numbers in linear time:
fibs = 0 : 1 : zipWith (+) fibs (tail fibs)
The infinite list is produced by corecursion — the latter values of the list are computed on demand starting from the initial two items 0 and 1. This kind of a definition is an instance of lazy evaluation and an important part of Haskell programming. For an example of how the evaluation evolves, the following illustrates the values of fibs and tail fibs after the computation of six items and shows how zipWith (+) has produced four items and proceeds to produce the next item:
fibs = 0 : 1 : 1 : 2 : 3 : 5 : ... + + + + + + tail fibs = 1 : 1 : 2 : 3 : 5 : ... = = = = zipWith ... = 1 : 2 : 3 : 5 : 8 : ... fibs = 0 : 1 : 1 : 2 : 3 : 5 : 8 : ...
The same function, written using GHC's parallel list comprehension syntax (GHC extensions must be enabled using a special command-line flag '-fglasgow-exts'; see GHC's manual for more):
fibs = 0 : 1 : [ a+b | a <- fibs | b <- tail fibs ]
The factorial we saw previously can be written as a sequence of functions:
fac n = (foldl (.) id [\x -> x*k | k <- [1..n]]) 1
A remarkably concise function that returns the list of Hamming numbers in order:
hamming = 1 : map (*2) hamming # map (*3) hamming # map (*5) hamming where xxs@(x:xs) # yys@(y:ys) | x==y = x : xs#ys | x<y = x : xs#yys | x>y = y : xxs#ys
Like the various fibs solutions displayed above, this uses corecursion to produce a list of numbers on demand, starting from the base case of 1 and building new items based on the preceding part of the list.
In this case the producer is defined in a where clause as an infix operator represented by the symbol
#. Apart from the different application syntax, operators are like functions whose name consists of symbols instead of letters.
Each vertical bar
| starts a guard clause with a guard before the equals sign and the corresponding definition after the equals sign. Together, the branches define how # merges two ascending lists into one ascending list without duplicate items.
- See also for an example that prints text.
Criticism
While Haskell has many advanced features not found in many other programming languages, some of these features have been criticized as making the language too complex or difficult to understand. In addition, there are complaints stemming from the purity of Haskell and its theoretical roots.Jan-Willem Maessen, in 2002, and Simon Peyton Jones, in 2003, discussed problems associated with lazy evaluation while also acknowledging the theoretical motivation for it[9][10], in addition to purely practical considerations such as improved performance.[11] They note that, in addition to adding some performance overhead, laziness makes it more difficult for programmers to reason about the performance of their code (specifically with regard to space usage).
Bastiaan Heeren, Daan Leijen, and Arjan van IJzendoorn in 2003 also observed some stumbling blocks for Haskell learners, "The subtle syntax and sophisticated type system of Haskell are a double edged sword -- highly appreciated by experienced programmers but also a source of frustration among beginners, since the generality of Haskell often leads to cryptic error messages." [12] To address these, they developed an advanced interpreter called Helium which improved the user-friendliness of error messages by limiting the generality of some Haskell features, and in particular removing support for type classes.
Implementations
The following all comply fully, or very nearly, with the Haskell 98 standard, and are distributed under open source licenses. There are currently no proprietary Haskell implementations.- The Glasgow Haskell Compiler compiles to native code on a number of different architectures—as well as to ANSI C—using C-- as an intermediate language. GHC is probably the most popular Haskell compiler, and there are quite a few useful libraries (e.g. bindings to OpenGL) that will only work with GHC.
- Gofer was an educational version of Haskell, developed by Mark Jones. It was supplanted by Hugs (see below).
- HBC is another native-code Haskell compiler. It has not been actively developed for some time, but is still usable.
- Helium is a newer dialect of Haskell. The focus is on making it easy to learn by providing clearer error messages. It currently lacks typeclasses, rendering it incompatible with many Haskell programs.
- Hugs, the Haskell User's Gofer System, is a bytecode interpreter. It offers fast compilation of programs and reasonable execution speed. It also comes with a simple graphics library. Hugs is good for people learning the basics of Haskell, but is by no means a "toy" implementation. It is the most portable and lightweight of the Haskell implementations.
- Jhc is a Haskell compiler written by John Meacham emphasising speed and efficiency of generated programs as well as exploration of new program transformations.
- nhc98 is another bytecode compiler, but the bytecode runs significantly faster than with Hugs. Nhc98 focuses on minimizing memory usage, and is a particularly good choice for older, slower machines.
- Yhc, the York Haskell Compiler is a fork of nhc98, with the goals of being simpler, more portable, more efficient and integrating support for Hat, the Haskell tracer.
See also
- O'Haskell — an extension of Haskell adding object-orientation and concurrent programming support.
- Pugs — a compiler and interpreter for the Perl 6 programming language
- LOLITA and Darcs — large applications written in Haskell
- Xmonad — a window manager written in Haskell (under 500 lines)
- Jaskell — a functional scripting programming language that runs in Java VM
- Curry — a language based on Haskell
References
1. ^ [2]
2. ^ Preface. Haskell 98 Language and Libraries: The Revised Report (December 2002).
3. ^ The History of Haskell.
4. ^ Simon Peyton Jones (editor) (December 2002). Haskell 98 Language and Libraries: The Revised Report.
5. ^ .
6. ^ Welcome to Haskell'. The Haskell' Wiki.
7. ^ list comprehension has been adopted by Python (programming language)
8. ^ Linspire/Freespire Core OS Team and Haskell. Debian Haskell mailing list (May 2006).
9. ^ Jan-Willem Maessen. Eager Haskell: Resource-bounded execution yields efficient iteration. Proceedings of the 2002 ACM SIGPLAN workshop on Haskell.
10. ^ Simon Peyton Jones. Wearing the hair shirt: a retrospective on Haskell. Invited talk at POPL 2003.
11. ^ Lazy evaluation can lead to excellent performance, such as in The Computer Language Benchmarks Game[3]
12. ^ Bastiaan Heeren, Daan Leijen, Arjan van IJzendoorn. Helium, for learning Haskell. Proceedings of the 2003 ACM SIGPLAN workshop on Haskell.
2. ^ Preface. Haskell 98 Language and Libraries: The Revised Report (December 2002).
3. ^ The History of Haskell.
4. ^ Simon Peyton Jones (editor) (December 2002). Haskell 98 Language and Libraries: The Revised Report.
5. ^ .
6. ^ Welcome to Haskell'. The Haskell' Wiki.
7. ^ list comprehension has been adopted by Python (programming language)
8. ^ Linspire/Freespire Core OS Team and Haskell. Debian Haskell mailing list (May 2006).
9. ^ Jan-Willem Maessen. Eager Haskell: Resource-bounded execution yields efficient iteration. Proceedings of the 2002 ACM SIGPLAN workshop on Haskell.
10. ^ Simon Peyton Jones. Wearing the hair shirt: a retrospective on Haskell. Invited talk at POPL 2003.
11. ^ Lazy evaluation can lead to excellent performance, such as in The Computer Language Benchmarks Game[3]
12. ^ Bastiaan Heeren, Daan Leijen, Arjan van IJzendoorn. Helium, for learning Haskell. Proceedings of the 2003 ACM SIGPLAN workshop on Haskell.
External links
- HaskellWiki - The Haskell Home Page
- A History of Haskell: being lazy with class - History of Haskell
- Haskell vs. Ada vs. C++ vs. Awk vs. ... An Experiment in Software Prototyping Productivity (a PostScript file)
- The Evolution of a Haskell Programmer - a slightly humorous overview of different programming styles available in Haskell
- An Online Bibliography of Haskell Research
- ePolyglot - combining Haskell, Python and Eiffel
Tutorials
- Programming in Haskell by Graham Hutton
- Yet Another Haskell Tutorial - a good Haskell tutorial by Hal Daume III; assumes much less prior knowledge than the official tutorial
- A Gentle Introduction to Haskell 98 (a more advanced tutorial, also available as pdf file)
- Haskell Tutorial for C Programmers by Eric Etheridge
A programming paradigm is a fundamental style of programming regarding how solutions to problems are to be formulated in a programming language. (Compare with a methodology, which is a style of solving specific software engineering problems).
..... Click the link for more information.
..... Click the link for more information.
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 with the imperative programming style that emphasizes changes in state.
..... Click the link for more information.
..... Click the link for more information.
Simon Peyton Jones (born in South Africa in 1958) is a British computer scientist who researches the implementation and applications of functional programming languages, particularly lazy functional languages.
..... Click the link for more information.
..... Click the link for more information.
Philip Wadler is a computer scientist well-known for his contributions to programming language design and type theory. In particular, he has contributed to the theory behind functional programming and the use of monads in functional programming, the design of the purely functional
..... Click the link for more information.
..... Click the link for more information.
In computer science, a type system defines how a programming language classifies values and expressions into types, how it can manipulate those types and how they interact.
..... Click the link for more information.
..... Click the link for more information.
In computer science, a type system defines how a programming language classifies values and expressions into types, how it can manipulate those types and how they interact.
..... Click the link for more information.
..... Click the link for more information.
In computer science and computer programming, the term strong typing is used to describe those situations where programming languages specify one or more restrictions on how operations involving values having different datatypes can be intermixed.
..... Click the link for more information.
..... Click the link for more information.
Type inference is a feature present in some strongly statically typed programming languages. It is often characteristic of — but not limited to — functional programming languages in general.
..... Click the link for more information.
..... Click the link for more information.
Implementation is the realization of an application, or execution of a plan, idea, model, design, specification, standard, algorithm, or policy.
In computer science, an implementation is a realization of a technical specification or algorithm as a program, software
..... Click the link for more information.
In computer science, an implementation is a realization of a technical specification or algorithm as a program, software
..... Click the link for more information.
Glasgow Haskell Compiler (or GHC) is an open source native code compiler for the functional programming language Haskell.
..... Click the link for more information.
History
GHC originally started in 1989 as a prototype, written in LML (Lazy ML) by Kevin Hammond at the University of Glasgow...... Click the link for more information.
Hugs (Haskell User's Gofer System) (also Hugs 98) is a bytecode interpreter for the functional programming language Haskell. Hugs is the successor to Gofer, and was originally derived from Gofer version 2.30b.
..... Click the link for more information.
..... Click the link for more information.
The York Haskell Compiler (or Yhc) is an open source bytecode compiler for the functional programming language Haskell; it primarily targets the Haskell '98 standard. It is one of the four main Haskell compilers (behind GHC, Hugs and nhc98).
..... Click the link for more information.
..... Click the link for more information.
A dialect of a programming language is a (relatively small) variation or extension of the language that does not change its intrinsic nature. With languages such as Scheme and Forth, standards may be considered insufficient, inadequate or even illegitimate by implementors, so often
..... Click the link for more information.
..... Click the link for more information.
Helium is a compiler and a dialect of the functional programming language Haskell. It has been designed to make learning Haskell easier by giving clearer error messages. It is being developed at Utrecht University, Netherlands, primarily by Arjan van IJzendoorn, Daan Leijen,
..... Click the link for more information.
..... Click the link for more information.
Gofer is an implementation of the Haskell programming language intended for educational purposes. Gofer is GO(od) F(or) E(quational) R(easoning). It has since been replaced by Hugs [1] .
..... Click the link for more information.
..... Click the link for more information.
Miranda
Paradigm: non-strict, functional, declarative
Appeared in: 1985
Designed by: David Turner
Developer: Research Software Ltd
Typing discipline: strong, static
Major implementations: Miranda
Influenced by: KRC, ML, SASL
..... Click the link for more information.
Paradigm: non-strict, functional, declarative
Appeared in: 1985
Designed by: David Turner
Developer: Research Software Ltd
Typing discipline: strong, static
Major implementations: Miranda
Influenced by: KRC, ML, SASL
..... Click the link for more information.
ML
Paradigm: multi-paradigm: imperative, functional
Appeared in: 1973
Designed by: Robin Milner & others at the University of Edinburgh
Typing discipline: static, strong, inferred
Dialects: Standard ML, OCaml, F#
Influenced by: ISWIM
..... Click the link for more information.
Paradigm: multi-paradigm: imperative, functional
Appeared in: 1973
Designed by: Robin Milner & others at the University of Edinburgh
Typing discipline: static, strong, inferred
Dialects: Standard ML, OCaml, F#
Influenced by: ISWIM
..... Click the link for more information.
Scala
Paradigm: multi-paradigm: functional, object-oriented
Appeared in: 2003
Designed by: Martin Odersky
Developer: Programming Methods Laboratory of EPFL
Typing discipline: static, strong
Major implementations: Scala
..... Click the link for more information.
Paradigm: multi-paradigm: functional, object-oriented
Appeared in: 2003
Designed by: Martin Odersky
Developer: Programming Methods Laboratory of EPFL
Typing discipline: static, strong
Major implementations: Scala
..... Click the link for more information.
A website (alternatively, Web site or web site) is a collection of Web pages, images, videos or other digital assets that is hosted on one or several Web server(s), usually accessible via the Internet, cell phone or a LAN.
..... Click the link for more information.
..... Click the link for more information.
This article is written like a personal reflection or and may require .
Please [ improve this article] by rewriting this article in an . (, talk)
Please [ improve this article] by rewriting this article in an . (, talk)
Purely functional
..... Click the link for more information.
A programming language is an artificial language that can be used to control the behavior of a machine, particularly a computer. Programming languages, like natural languagess, are defined by syntactic and semantic rules which describe their structure and meaning respectively.
..... Click the link for more information.
..... Click the link for more information.
A strict programming language is one in which only strict functions may be defined by the user. A non-strict programming language is one that allows the user to define non-strict functions, and hence may allow lazy evaluation.
..... Click the link for more information.
..... Click the link for more information.
Logic (from Classical Greek λόγος logos; meaning word, thought, idea, argument, account, reason, or principle) is the study of the principles and criteria of valid inference and demonstration.
..... Click the link for more information.
..... Click the link for more information.
Haskell Brooks Curry (September 12, 1900, Millis, Massachusetts – September 1, 1982, State College, Pennsylvania) was an American mathematician and logician.
The son of educator Samuel Silas Curry, he was educated at Harvard University and received a Ph.D.
..... Click the link for more information.
The son of educator Samuel Silas Curry, he was educated at Harvard University and received a Ph.D.
..... Click the link for more information.
Miranda
Paradigm: non-strict, functional, declarative
Appeared in: 1985
Designed by: David Turner
Developer: Research Software Ltd
Typing discipline: strong, static
Major implementations: Miranda
Influenced by: KRC, ML, SASL
..... Click the link for more information.
Paradigm: non-strict, functional, declarative
Appeared in: 1985
Designed by: David Turner
Developer: Research Software Ltd
Typing discipline: strong, static
Major implementations: Miranda
Influenced by: KRC, ML, SASL
..... Click the link for more information.
Miranda
Paradigm: non-strict, functional, declarative
Appeared in: 1985
Designed by: David Turner
Developer: Research Software Ltd
Typing discipline: strong, static
Major implementations: Miranda
Influenced by: KRC, ML, SASL
..... Click the link for more information.
Paradigm: non-strict, functional, declarative
Appeared in: 1985
Designed by: David Turner
Developer: Research Software Ltd
Typing discipline: strong, static
Major implementations: Miranda
Influenced by: KRC, ML, SASL
..... Click the link for more information.
An open standard is a standard that is publicly available and has various rights to use associated with it.
The terms "open" and "standard" have a wide range of meanings associated with their usage.
..... Click the link for more information.
The terms "open" and "standard" have a wide range of meanings associated with their usage.
..... Click the link for more information.
library is a collection of subprograms used to develop software. Libraries contain "helper" code and data, which provide services to independent programs. This allows code and data to be shared and changed in a modular fashion.
..... Click the link for more information.
..... Click the link for more information.
Hugs (Haskell User's Gofer System) (also Hugs 98) is a bytecode interpreter for the functional programming language Haskell. Hugs is the successor to Gofer, and was originally derived from Gofer version 2.30b.
..... Click the link for more information.
..... Click the link for more information.
Glasgow Haskell Compiler (or GHC) is an open source native code compiler for the functional programming language Haskell.
..... Click the link for more information.
History
GHC originally started in 1989 as a prototype, written in LML (Lazy ML) by Kevin Hammond at the University of Glasgow...... Click the link for more information.
This article is copied from an article on Wikipedia.org - the free encyclopedia created and edited by online user community. The text was not checked or edited by anyone on our staff. Although the vast majority of the wikipedia encyclopedia articles provide accurate and timely information please do not assume the accuracy of any particular article. This article is distributed under the terms of GNU Free Documentation License.
Herod_Archelaus
