Jump to content
 







Main menu
   


Navigation  



Main page
Contents
Current events
Random article
About Wikipedia
Contact us
Donate
 




Contribute  



Help
Learn to edit
Community portal
Recent changes
Upload file
 








Search  

































Create account

Log in
 









Create account
 Log in
 




Pages for logged out editors learn more  



Contributions
Talk
 



















Contents

   



(Top)
 


1 History  





2 Features and extensions  





3 Applications  





4 Examples  



4.1  More complex examples  







5 Criticism  





6 Implementations  





7 See also  





8 References  





9 External links  



9.1  Tutorials  
















Haskell






العربية
Azərbaycanca

Беларуская
Български
Català
Čeština
Dansk
Deutsch
Eesti
Ελληνικά
Español
Esperanto
Euskara
فارسی
Français
Galego

ि
Hrvatski
Ido
Bahasa Indonesia
Íslenska
Italiano
עברית
Қазақша
Latina
Latviešu
Lëtzebuergesch
Magyar


Bahasa Melayu
Nederlands

Norsk bokmål

Polski
Português
Română
Русский
Simple English
Slovenčina
Slovenščina
Српски / srpski
Suomi
Svenska

Türkçe
Українська
Tiếng Vit

 

Edit links
 









Article
Talk
 

















Read
Edit
View history
 








Tools
   


Actions  



Read
Edit
View history
 




General  



What links here
Related changes
Upload file
Special pages
Permanent link
Page information
Cite this page
Get shortened URL
Download QR code
Wikidata item
 




Print/export  



Download as PDF
Printable version
 




Print/export  







In other projects  



Wikimedia Commons
Wikibooks
Wikiquote
Wikiversity
 
















Appearance
   

 






From Wikipedia, the free encyclopedia
 


This is an old revision of this page, as edited by Kowey (talk | contribs)at02:10, 23 December 2006 (Tutorials: update yaht link). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
(diff)  Previous revision | Latest revision (diff) | Newer revision  (diff)

Haskell
Paradigmfunctional, non-strict, modular
First appeared1990
Typing disciplinestrong, static
Websitewww.haskell.org
Major implementations
GHC, Hugs, NHC, JHC, Yhc
Dialects
--
Influenced by
Miranda, ML, Gofer
Influenced
Python

Haskell is a standardized pure functional programming language with non-strict semantics, named after the logician Haskell Curry.

History

The direct predecessor of Haskell was Miranda, devised in 1985.

In 1987 there existed more than a dozen competing non-strict, purely functional programming languages. A meeting was held at the conference on Functional Programming Languages and Computer Architecture (FPCA '87) in Portland, Oregon, during which strong consensus was found among the participants that a committee should be formed for the definition of an open standard such language. 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.[1] The first version of Haskell ("Haskell 1.0") was defined in 1990.[2] 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 by the addition and incorporation of experimental features.

The Haskell 98 language standard was originally published as "The Haskell 98 Report" in January 1999. A revised version was published in January 2003 as "Haskell 98 Language and Libraries: The Revised Report".[3] 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 started.[4] This process is intended to produce a minor revision of Haskell 98.[5]

Features and extensions

Characteristic features of Haskell include pattern matching, currying, list comprehensions, 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.

The language is, as of 2002, the lazy functional language on which the most research is being performed.[citation needed] 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 deviation from Haskell is in the 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 forthcoming Perl 6 language with an interpreter and compilers that proved useful already after just a few months of its writing. Darcs is a revision control system, with several innovative features. Linspire GNU/Linux chose Haskell for system tools development.[6]

Examples

A simple example that is often used to demonstrate the syntax of functional languages is the factorial function, shown in Haskell:

fac :: Integer -> Integer
fac 0 = 1
fac n | n > 0 = n * fac (n-1)

Or in a single line:

fac n = if n > 0 then n * fac (n-1) else 1

This describes the factorial as a recursive function, with a single 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.

Aguard 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 oh (see function composition), and indeed, it is not an assignment of a 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 whereorlet..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 on a single line to be used later.

More complex examples

A simple RPN calculator expressed with a higher-order function 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; 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 wikibooks:Transwiki:List of hello world programs#Haskell for an example that prints text.

Criticism

Haskell has many advanced features not found in many other programming languages, but some of these features have been criticized as making the language too complex or difficult to understand. In particular, critiques of functional programming languages and non-mainstream programming languages also apply to Haskell. 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 discuss problems associated with lazy evaluation whilst also acknowledging the theoretical motivation for it.[7][8] 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 space usage).

Bastiaan Heeren, Daan Leijen, and Arjan van IJzendoorn in 2003 also observed some stumbling blocks for Haskell learners. [9] 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 commercial Haskell implementations.

See also

References

  1. ^ "Preface". Haskell 98 Language and Libraries: The Revised Report. 2002. {{cite web}}: Unknown parameter |month= ignored (help)
  • ^ "The History of Haskell".
  • ^ Simon Peyton Jones (editor) (2002). "Haskell 98 Language and Libraries: The Revised Report". Retrieved 2006-08-03. {{cite web}}: |author= has generic name (help); Unknown parameter |month= ignored (help)
  • ^ "Future development of Haskell". Retrieved 2006-08-03.
  • ^ "Welcome to Haskell'". The Haskell' Wiki. Retrieved 2006-08-03.
  • ^ "Linspire/Freespire Core OS Team and Haskell". Debian Haskell mailing list. 2006. Retrieved 2006-08-03. {{cite web}}: Unknown parameter |month= ignored (help)
  • ^ Jan-Willem Maessen. Eager Haskell: Resource-bounded execution yields efficient iteration. Proceedings of the 2002 ACM SIGPLAN workshop on Haskell.
  • ^ Simon Peyton Jones. Wearing the hair shirt: a retrospective on Haskell. Invited talk at POPL 2003.
  • ^ Bastiaan Heeren, Daan Leijen, Arjan van IJzendoorn. Helium, for learning Haskell. Proceedings of the 2003 ACM SIGPLAN workshop on Haskell.
  • External links

    Tutorials


    Retrieved from "https://en.wikipedia.org/w/index.php?title=Haskell&oldid=96029451"

    Categories: 
    Haskell programming language family
    Programming languages
    Functional languages
    Declarative programming languages
    Hidden categories: 
    CS1 errors: unsupported parameter
    CS1 errors: generic name
    All articles with unsourced statements
    Articles with unsourced statements
    Pages using reflist with unknown parameters
     



    This page was last edited on 23 December 2006, at 02:10 (UTC).

    This version of the page has been revised. Besides normal editing, the reason for revision may have been that this version contains factual inaccuracies, vandalism, or material not compatible with the Creative Commons Attribution-ShareAlike License.



    Privacy policy

    About Wikipedia

    Disclaimers

    Contact Wikipedia

    Code of Conduct

    Developers

    Statistics

    Cookie statement

    Mobile view



    Wikimedia Foundation
    Powered by MediaWiki