# Example code

### From HaskellWiki

DonStewart (Talk | contribs) (a link to the 1.2 prelude, nice basics in there) |
DonStewart (Talk | contribs) (a modern Prelude.hs) |
||

Line 9: | Line 9: | ||

* [http://darcs.haskell.org/packages/base/Data/List.hs List.hs], the standard [a] type | * [http://darcs.haskell.org/packages/base/Data/List.hs List.hs], the standard [a] type | ||

+ | * [http://www.cse.unsw.edu.au/~dons/data/Prelude.hs A Haskell98 Prelude.hs], foundational Haskell library | ||

* [http://darcs.haskell.org/packages/base/Data/Maybe.hs Maybe.hs], the Maybe a type | * [http://darcs.haskell.org/packages/base/Data/Maybe.hs Maybe.hs], the Maybe a type | ||

* [http://darcs.haskell.org/packages/base/Data/Map.hs Map.hs], the standard finite map | * [http://darcs.haskell.org/packages/base/Data/Map.hs Map.hs], the standard finite map | ||

Line 25: | Line 26: | ||

* [http://darcs.haskell.org/packages/ndp/Data/Array/Parallel/Stream/Flat/Combinators.hs Combinators.hs], array combinators | * [http://darcs.haskell.org/packages/ndp/Data/Array/Parallel/Stream/Flat/Combinators.hs Combinators.hs], array combinators | ||

* [http://www.cse.unsw.edu.au/~dons/code/lambdabot/scripts/SmallCheck.hs SmallCheck.hs], a testing framework | * [http://www.cse.unsw.edu.au/~dons/code/lambdabot/scripts/SmallCheck.hs SmallCheck.hs], a testing framework | ||

− | |||

* [http://haskell.org/haskellwiki/Darcs_repositories More code ...] | * [http://haskell.org/haskellwiki/Darcs_repositories More code ...] | ||

## Revision as of 04:58, 17 September 2006

To get a feel for what real world Haskell looks like, here are some examples from various popular Haskell projects.

### 1 Library code

Library code usually differs from application code: it is often highly structured, and documented with haddock, and can be rather optimised. Some instructive examples:

- List.hs, the standard [a] type
- A Haskell98 Prelude.hs, foundational Haskell library
- Maybe.hs, the Maybe a type
- Map.hs, the standard finite map
- Tree.hs, a tree type
- Graph.hs, a graph type
- Monad.hs, basic monadic support
- QuickCheck.hs, a testing framework
- PrettyPrint.hs, a pretty printing library
- StateT.hs, a monad transformer library
- Music.lhs, a music composition system (literate latex-style Haskell)
- Dfa.lhs, finite automata (literate Bird-style Haskell)
- RedBlackTree.hs, a red-black tree
- Prime.hs, prime numbers
- Foldable.hs, traversable data structures
- ByteString.hs, high-performance string type
- Combinators.hs, array combinators
- SmallCheck.hs, a testing framework
- More code ...

### 2 Application code

Code from popular Haskell applications. Such code often makes use of a monadic IO, and sometimes other advanced features such as concurrency:

- Darcs, a revision control system (uses literate latex Haskell style)
- Pugs, a perl6 implementation
- Yi, a text editor
- Conjure, a bittorrent client
- DownNova, a file downloading program
- cpphs, an implementation of the C preprocessor
- GHC, a Haskell compiler (literate latex style)
- Djinn, a theorem prover
- c2hs, a C to Haskell interface generator
- Lambdabot, an IRC bot
- hmp3, an curses mp3 player
- More code ...

### 3 Wiki examples

Here is a list of other random code collected on this wiki, replacing CodeOnTheWiki. Contributors of code to the old area are encouraged to bring their code over here. This should only be done by the original author because anything on these pages is automatically licensed under the Simple Permissive License (HaskellWiki:Copyrights).

Most examples are roughly intermediate to advanced in difficulty.

- Prelude extensions: Simple things you've always wished were in the Prelude.
- Gallery: Complete small programs.
- Blow your mind: Short, useful, cool, magical examples, which should incite the reader's curiosity and (hopefully) lead him to a deeper understanding of advanced Haskell concepts.
- Sudoku: Solvers for popular puzzle Sudoku
- NewMonads: Useful monads that are not in the main library.
- PrincipalVariationSearch: Principal variation search
- Shootout Entries: Examples still on the old wiki for the The Computer Language Shootout Benchmarks.
- Ralf Hinze maintains a Haskell software page