Difference between revisions of "Example code"

From HaskellWiki
Jump to: navigation, search
m
(People are using this page to cite what real haskell looks like. Better actually put up some good examples)
Line 1: Line 1:
== Example Code ==
 
  +
To get a feel for what real world Haskell looks like, here are some
  +
examples from various popular Haskell projects.
   
This is a collection of example code. It is intended to take the role of the old Wiki area [http://haskell.org/hawiki/CodeOnTheWiki 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]]).
 
  +
=== Library code ===
  +
  +
Library code usually differs from application code: it is often highly
  +
structured, and documented with [http://haskell.org/haddock haddock],
  +
and can be rather optimised.
  +
  +
[http://darcs.haskell.org/packages/base/Data/List.hs List.hs]
  +
  +
[http://darcs.haskell.org/packages/base/Data/Map.hs Map.hs]
  +
  +
[http://darcs.haskell.org/packages/base/Control/Monad.hs Monad.hs]
  +
  +
[http://darcs.haskell.org/packages/QuickCheck/Test/QuickCheck.hs QuickCheck.hs]
  +
  +
[http://darcs.haskell.org/packages/base/Text/PrettyPrint/HughesPJ.hs PrettyPrint.hs]
  +
  +
[http://darcs.haskell.org/packages/monads/Monad/StateT.hs StateT.hs]
  +
  +
[http://www.ninebynine.org/Software/Swish-0.2.1/HaskellRDF/Dfa/Dfa.lhs Dfa.lhs]
  +
  +
[http://www.polyomino.f2s.com/david/haskell/hs/redblacktree.hs.txt RedBlackTree.hs]
  +
  +
[http://andrew.bromage.org/darcs/numbertheory/Math/Prime.hs Prime.hs]
  +
  +
[http://darcs.haskell.org/packages/base/Data/Foldable.hs Foldable.hs]
  +
  +
[http://darcs.haskell.org/packages/base/Data/ByteString.hs ByteString.hs]
  +
  +
[http://darcs.haskell.org/packages/ndp/Data/Array/Parallel/Stream/Flat/Combinators.hs Combinators.hs]
  +
  +
=== Application code ===
  +
  +
Code from popular Haskell applications:
  +
  +
[http://www.abridgegame.org/repos/darcs-unstable/PatchCommute.lhs Darcs], a revision control system (uses literate Haskell style)
  +
  +
[http://svn.openfoundry.org/pugs/src/Pugs/Eval.hs Pugs], a perl6 implementation
  +
  +
[http://www.cse.unsw.edu.au/~dons/code/yi/Yi/Core.hs Yi], a text editor
  +
  +
[http://j.mongers.org/pub/haskell/darcs/conjure/Conjure/Torrent.hs Conjure], a bittorrent client
  +
  +
[http://darcs.haskell.org/~lemmih/downNova/src/Torrent.hs DownNova], a file downloading program
  +
  +
[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://www.augustsson.net/Darcs/Djinn/LJT.hs Djinn], a theorem prover
  +
  +
[http://darcs.haskell.org/c2hs/c2hs/c/CTrav.hs c2hs], a C to Haskell interface generator
  +
  +
[http://www.cse.unsw.edu.au/~dons/code/lambdabot/LBState.hs Lambdabot], an IRC bot
  +
  +
[http://www.cse.unsw.edu.au/~dons/code/hmp3/Core.hs hmp3], an curses mp3 player
  +
  +
=== Wiki examples===
  +
  +
Here is a list of other random code collected on this wiki, replacing
  +
[http://haskell.org/hawiki/CodeOnTheWiki 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.
 
[[Prelude extensions]]: Simple things you've always wished were in the Prelude.

Revision as of 05:28, 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.

List.hs

Map.hs

Monad.hs

QuickCheck.hs

PrettyPrint.hs

StateT.hs

Dfa.lhs

RedBlackTree.hs

Prime.hs

Foldable.hs

ByteString.hs

Combinators.hs

Application code

Code from popular Haskell applications:

Darcs, a revision control system (uses literate 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

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.