Difference between revisions of "Example code"

From HaskellWiki
Jump to navigation Jump to search
(wibble)
(wibbles)
Line 1: Line 1:
 
To get a feel for what real world Haskell looks like, here are some
 
To get a feel for what real world Haskell looks like, here are some
examples from various popular Haskell projects. Haskell code comes in
+
examples from various popular Haskell projects.
three flavours: plane, [[Literate Haskell|literate Bird-style]], and
 
literate latex style. Additionally, cpp is sometimes used for
 
preprocessing.
 
   
 
=== Library code ===
 
=== Library code ===
Line 27: Line 24:
 
[http://darcs.haskell.org/packages/monads/Monad/StateT.hs StateT.hs], a monad transformer library
 
[http://darcs.haskell.org/packages/monads/Monad/StateT.hs StateT.hs], a monad transformer library
   
[http://darcs.haskell.org/haskore/src/Haskore/Music.lhs Music.hs], a music composition system
+
[http://darcs.haskell.org/haskore/src/Haskore/Music.lhs Music.lhs], a music composition system (literate latex-style Haskell)
   
[http://www.ninebynine.org/Software/Swish-0.2.1/HaskellRDF/Dfa/Dfa.lhs Dfa.lhs], finite automata
+
[http://www.ninebynine.org/Software/Swish-0.2.1/HaskellRDF/Dfa/Dfa.lhs Dfa.lhs], finite automata (literate Bird-style Haskell)
   
 
[http://www.polyomino.f2s.com/david/haskell/hs/redblacktree.hs.txt RedBlackTree.hs], a red-black tree
 
[http://www.polyomino.f2s.com/david/haskell/hs/redblacktree.hs.txt RedBlackTree.hs], a red-black tree
Line 50: Line 47:
 
monadic IO, and sometimes other advanced features (such as concurrency):
 
monadic IO, and sometimes other advanced features (such as concurrency):
   
[http://www.abridgegame.org/repos/darcs-unstable/PatchCommute.lhs Darcs], a revision control system (uses literate Haskell style)
+
[http://www.abridgegame.org/repos/darcs-unstable/PatchCommute.lhs Darcs], a revision control system (uses literate latex Haskell style)
   
 
[http://svn.openfoundry.org/pugs/src/Pugs/Eval.hs Pugs], a perl6 implementation
 
[http://svn.openfoundry.org/pugs/src/Pugs/Eval.hs Pugs], a perl6 implementation
Line 62: Line 59:
 
[http://www.cs.york.ac.uk/fp/darcs/cpphs/Language/Preprocessor/Cpphs/Tokenise.hs cpphs], an implementation of the C preprocessor
 
[http://www.cs.york.ac.uk/fp/darcs/cpphs/Language/Preprocessor/Cpphs/Tokenise.hs cpphs], an implementation of the C preprocessor
   
[http://darcs.haskell.org/ghc/compiler/simplCore/Simplify.lhs GHC], a Haskell compiler
+
[http://darcs.haskell.org/ghc/compiler/simplCore/Simplify.lhs GHC], a Haskell compiler (literate latex style)
   
 
[http://www.augustsson.net/Darcs/Djinn/LJT.hs Djinn], a theorem prover
 
[http://www.augustsson.net/Darcs/Djinn/LJT.hs Djinn], a theorem prover

Revision as of 07:51, 14 September 2006

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

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

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

A large collection of online Haskell source

Application code

Code from popular Haskell applications. Such code often makes use of an 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

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).

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.