background preloader

Haskell - references

Facebook Twitter

Haskell - Wikibooks, collection of open-content textbooks. Haskell is a functional programming language. If you've programmed before and would like to see a little bit of how Haskell works and is different from other programming languages, see the overview. Haskell is unique in two ways. First, it is a pure functional programming language. If you have a function and you call it twice in two different places with the same arguments then it will return exactly the same value both times. Second, Haskell provides a very modern type system which incorporates features like typeclasses and generalized algebraic data types. (we hope terms like these will roll smoothly off your tongue by the time you're done.) So, why do Haskellers like their language? In this book we aim to introduce you both to the Haskell language, from the very basics to the most advanced features, and to computer programming in general.

Overview[edit] Beginner's Track[edit] Most chapters contain exercises where you can test yourself on what you learned in that chapter. Syntactic sugar. Applications and libraries. The number of Haskell packages is growing rapidly. The section 'Haskell library collections' gives an ordering of all these packages by relative importance.

In the section 'Haskell applications and libraries' an ordering by category is given. Finally some guidelines for developers of new packages are presented. 1 Haskell library collections 1.1 Haskell Prelude The most important Haskell library is called the Prelude. It is implicitly imported by default, and includes the most commonly used functions. 1.2 The Haskell 2010 libraries The Haskell 2010 Language and library specification defines a set of libraries with basic functionality which all Haskell implementations should support, including the Prelude. Haskell modules that almost everybody uses are in this group, for example: Control.Monad, Data.List and System.IO. 1.3 The GHC standard libraries GHC comes with an expanded version of the Haskell 2010 libraries. 1.4 Haskell Platform libraries 1.5 The Hackage database Built with Cabal.

Haskell Hierarchical Libraries. Import. The statement is used to import functions and other definitions from another module. The shortest form of the import statement is that imports the named module (in this case ). However, there are more options: Modules can be imported qualified (forcing an obligatory namespace qualifier to imported identifiers). Some identifiers can be skipped via the hiding clause. The module namespace can be renamed, with an as clause. Getting all of this straight in your head is quite tricky, so here is a table (lifted directly from the language reference manual) that roughly summarises the various possibilities: Supposing that the module exports three functions named , and ...

Note that multiple import statements for the same module are also allowed, so it is possible to mix and match styles if its so desired (for example, importing operators directly and functions qualified) 1 Hiding Prelude By default, every module implicitly imports . Module Mod where import Prelude hiding (zip) zip = {- ... -} Prelude. Parsing of Strings, producing values. Minimal complete definition: readsPrec (or, for GHC only, readPrec) Derived instances of Read make the following assumptions, which derived instances of Text.Show.Show obey: If the constructor is defined to be an infix operator, then the derived Read instance will parse only infix applications of the constructor (not the prefix form).

Associativity is not used to reduce the occurrence of parentheses, although precedence may be. For example, given the declarations infixr 5 :^: data Tree a = Leaf a | Tree a :^: Tree a the derived instance of Read in Haskell 98 is equivalent to instance (Read a) => Read (Tree a) where readsPrec d r = readParen (d > app_prec) (\r -> [(Leaf m,t) | ("Leaf",s) <- lex r, (m,t) <- readsPrec (app_prec+1) s]) r ++ readParen (d > up_prec) (\r -> [(u:^:v,w) | (u,s) <- readsPrec (up_prec+1) r, (":^:",t) <- lex s, (v,w) <- readsPrec (up_prec+1) t]) r where app_prec = 10 up_prec = 5 Note that right-associativity of :^: is unused.

YAML - Hackage

Haskell - langref.org.