|
Haskell occurs as standardized pure functional programming language with non-strict semantics. Known as fallowing a logistician Haskell Curry, it was created by a committee formed inside 1987 for the express purpose of defining such a language. A straight predecessor of Haskell was Miranda from 1985.
A latest semi-official language standard is Haskell 98, designed to specify the minimum, personal version of the language for teaching & as a base for new extensions.
A language continues to develop chop-chop, by using Hugs and GHC (see following) representing a todays de facto standard.
Characterizing syntax features inside Haskell include pattern matching, currying, list comprehensions, guards, and definable operators. A language too supports recursive functions and algebraic data types, when well as lazy evaluation. Unique conception include monads, and type classes.
A combination of such features may produce functions which would be hard to write withwithin the procedural programing language nigh trivial to implement in Haskell.
A language is, when of 2002, the lazy functional language on which the virtually all search is existence performed. Many variants develop been developed: parallelizable versions from either MIT and Glasgow, both known as Parallel Haskell; supplementary parallel & distributed versions known as Distributed Haskell (formerly Goffin) & Eden; a speculatively evaluating version called Eager Haskell & many object oriented versions: Haskell++, O'Haskell and Mondrian.
Although Haskell has the relatively little user community, its strengths keep close at hand been easily applied to two or three projects. Autrijus Tang's Pugs is an implementation for the forthcoming Perl 6 language sustaining an interpreter & compilers that proved utile already when only two or three months of its writing. DARCS is a revision control system, by having many innovative features.
There exists too the Haskell-such as language that offers the recently method of trend lines for GUI development called Concurrent Clean. Its large deviation from either Haskell is in the have of uniqueness types for input as opposed to monads.
Examples
Anatomy of a Haskell function
A "Hello World" of functional languages is the factorial function. Verbalized when pure Haskell:
fac :: Integer -> Integer
fac Cipher = 1
fac north | n>0 = north * fac (north-One)
This describes a factorial as a recursive work, by having one terminating base pack. These are similar to the descriptions of factorials witnessed within math text. Tremendously of Haskell code is similar to maths within facility & syntax.
A number 1 line of a factorial work shown is optional, & describes the types of this work. It may be page through when a work fac (fac) has nature and severity (::) from either whole number to whole number (Whole number -> Integer). That is, it requires an whole number as an argument, & is restored a second whole number.
A 2nd line relies in pattern matching, an important a portion of Haskell programming. Note that parameters of the work are non around parentheses however separated by spaces. While a work's argument is Nought (zero) it may link to a whole number Ace (1). For everthing more legal actions a third line is tried. This is the recursion, and executes a work once more until a base pack is reached. The guard protects the third line from either blackball arguments that would process down unterminated.
A "Prelude" occurs as total of little functions correspondent to Hundred's standard library. Using the Prelude & writing in the "point free" (insert classic Haskell joke on this text) style of unspecified arguments, it becomes:
fac = product . enumFromTo 1
A above is some mathematical definitions like f = g o h (view function composition), and indeed, it's non an assignment of the value to the variable.
More complex examples
The elementary RPN calculator:
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 = (see y :: Float):xs
The work which comes back water of the Fibonacci numbers in linear time:
taradiddle = Cypher : Unity : (zipWith (+) tale (backside tarradiddle))
A equivalent work, presented using GHC's parallel list comprehension syntax:
tarradiddle = Nought : Single : [ a+b | a <- fibs | b <- tail fibs ]
The earlier factorial function, this time using 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
| xy = y : xxs#ys
Implementations
A resulting 100% comply fully, or even super about, by having a Haskell 98 standard, & come distributed under open source licences. There are presently there are no commercial Haskell implementations.
Hugs ([http://www.haskell.org/hugs/]) is a bytecode interpreter. It offers convenient compilation of computer software & sensible execution speed. It likewise go with the elementary graphics library. Clinch is adept for population learning the fundamentals of Haskell, however is not by a blame sight a "toy" implementation. These are a virtually all personal & lightweight of the Haskell implementations.
Glasgow Haskell Compiler ([http://www.haskell.org/ghc/]). the Glasgow Haskell Compiler compiles to indigen code in a total of different architectures, & can likewise compile to C. GHC is probably a virtually all popular Haskell compiler, & there are quite few utile libraries (e.g. bindings to OpenGL) that will simply function by having GHC.
nhc98 ([http://www.cs.york.ac.uk/fp/nhc98/]) is an additional bytecode compiler, however a bytecode diarrhea significantly sooner than using Squeeze. Nhc98 focuses in minimising memory usage, & occurs as particularly skillful selection for older, slower machines.
Jhc ([http://repetae.net/john/computer/jhc/]) the haskell compiler emphasising speed & efficiency of generated computer software besides when exploration of freshly program transformations.
Gofer An training version of Haskell, Gofer was developed by Mark Jones. It was supplanted by Clinch.
HBC ([http://www.cs.chalmers.se/~augustss/hbc/hbc.html]) is a second native-code Haskell compiler. It hasn't been actively developed for a select few period, however is however usable.
Atomic number 2 ([http://www.cs.uu.nl/helium/]) occurs as fresh accent of Haskell. A focus get on making it real life to study. It presently lacks typeclasses, making it incompatible by owning numerous Haskell software online.
Extensions
O'Haskell is an extension of Haskell adding object-orientation and concurrent programming support.
|