Haskell – Official Home Page: https://www.haskell.org


中文:http://www.haskellcn.org


Haskell


An advanced purely-functional programming language Declarative, statically typed code.

primes = filterPrime [2..] 
where filterPrime (p:xs) =
p : filterPrime [x | x <- xs, x `mod` p /= 0]

Features


Statically typed


Every expression in Haskell has a type which is determined at compile time. All the types composed together by function application have to match up. If they don’t, the program will be rejected by the compiler. Types become not only a form of guarantee, but a language for expressing the construction of programs.

Purely functional


Every function in Haskell is a function in the mathematical sense (i.e., “pure”). Even side-effecting IO operations are but a description of what to do, produced by pure code. There are no statements or instructions, only expressions which cannot mutate variables (local or global) nor access state like time or random numbers.

Type inference


You don’t have to explicitly write out every type in a Haskell program. Types will be inferred by unifying every type bidirectionally. However, you can write out types if you choose, or ask the compiler to write them for you for handy documentation.

Concurrent


Haskell lends itself well to concurrent programming due to its explicit handling of effects. Its flagship compiler, GHC, comes with a high-performance parallel garbage collector and light-weight concurrency library containing a number of useful concurrency primitives and abstractions.

Lazy


Functions don’t evaluate their arguments. This means that programs can compose together very well, with the ability to write control constructs (such as if/else) just by writing normal functions. The purity of Haskell code makes it easy to fuse chains of functions together, allowing for performance benefits.

Packages


Open source contribution to Haskell is very active with a wide range of packages available on the public package servers.

什么是Haskell?


Haskell 与其它语言不同,是一门纯粹的函数式编程语言(purely functional programming language)。在一般常见的命令式语言中,要执行操作的话是给电脑一组命令,而状态会随着命令的执行而改变。例如你指派变量 a 的值为 5,而随后做了其它天王终点事情之后 a 就可能变成其它值。有控制流程(control flow),你就可以重复执行操作。然而在纯粹函数式编程语言中,你不是像命令式语言那样命令电脑 【要做什么】,而是通过函数描述出总是【是什么】,如【阶乘是指比 1 到莫要个数的乘积】,【一个串列中数据的和】是指把第一个数字跟剩余数字的和相加。你用宣告函数是什么的形式来写程序。另外,变量(variable)一旦被指定,就不可以更改了,你已经说了 a 就是 5,就不能再说 a 是别的什么数。所有说,在纯粹函数式编程语言中函数能做的唯一事情就是利用引数计算结果,不会产生所谓的副作用(side effect)。一开始会觉得这限制很大,不过这也是它的优点所在。若以同样的参数调用同一个函数两次,得到的结果一定是相同的。这被称作引用透明(Referential Transparency)。如此一来编译器就可以理解程序的行为,你也很容易就验证一个函数的正确性,继而可以将一些简单的函数组合成更复杂的函数。