Difference between revisions of "Example code"
DonStewart (talk  contribs) (wibbles) 
DonStewart (talk  contribs) (fmt) 

Line 8:  Line 8:  
and can be rather optimised. Some instructive examples: 
and can be rather optimised. Some instructive examples: 

−  [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://darcs.haskell.org/packages/base/Data/Map.hs Map.hs], the standard finite map 

−  [http://darcs.haskell.org/packages/base/Data/ 
+  * [http://darcs.haskell.org/packages/base/Data/Tree.hs Tree.hs], a tree type 
−  +  * [http://darcs.haskell.org/packages/base/Data/Graph.hs Graph.hs], a graph type 

−  [http://darcs.haskell.org/packages/base/ 
+  * [http://darcs.haskell.org/packages/base/Control/Monad.hs Monad.hs], basic monadic support 
−  +  * [http://darcs.haskell.org/packages/QuickCheck/Test/QuickCheck.hs QuickCheck.hs], a testing framework 

−  [http://darcs.haskell.org/packages/base/ 
+  * [http://darcs.haskell.org/packages/base/Text/PrettyPrint/HughesPJ.hs PrettyPrint.hs], a pretty printing library 
−  +  * [http://darcs.haskell.org/packages/monads/Monad/StateT.hs StateT.hs], a monad transformer library 

−  [http://darcs.haskell.org/ 
+  * [http://darcs.haskell.org/haskore/src/Haskore/Music.lhs Music.lhs], a music composition system (literate latexstyle Haskell) 
−  +  * [http://www.ninebynine.org/Software/Swish0.2.1/HaskellRDF/Dfa/Dfa.lhs Dfa.lhs], finite automata (literate Birdstyle Haskell) 

−  [http:// 
+  * [http://www.polyomino.f2s.com/david/haskell/hs/redblacktree.hs.txt RedBlackTree.hs], a redblack tree 
−  +  * [http://andrew.bromage.org/darcs/numbertheory/Math/Prime.hs Prime.hs], prime numbers 

−  [http://darcs.haskell.org/packages/base/ 
+  * [http://darcs.haskell.org/packages/base/Data/Foldable.hs Foldable.hs], traversable data structures 
−  +  * [http://darcs.haskell.org/packages/base/Data/ByteString.hs ByteString.hs], highperformance string type 

−  [http://darcs.haskell.org/packages/ 
+  * [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:// 
+  * [http://haskell.org/haskellwiki/Darcs_repositories A large collection of online Haskell source] 
−  
−  [http://www.ninebynine.org/Software/Swish0.2.1/HaskellRDF/Dfa/Dfa.lhs Dfa.lhs], finite automata (literate Birdstyle Haskell) 

−  
−  [http://www.polyomino.f2s.com/david/haskell/hs/redblacktree.hs.txt RedBlackTree.hs], a redblack tree 

−  
−  [http://andrew.bromage.org/darcs/numbertheory/Math/Prime.hs Prime.hs], prime numbers 

−  
−  [http://darcs.haskell.org/packages/base/Data/Foldable.hs Foldable.hs], traversable data structures 

−  
−  [http://darcs.haskell.org/packages/base/Data/ByteString.hs ByteString.hs], highperformance string type 

−  
−  [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://haskell.org/haskellwiki/Darcs_repositories A large collection of online Haskell source] 

=== Application code === 
=== Application code === 

Line 31:  Line 31:  
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/darcsunstable/PatchCommute.lhs Darcs], a revision control system (uses literate latex Haskell style) 
+  * [http://www.abridgegame.org/repos/darcsunstable/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:// 
+  * [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:// 
+  * [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:// 
+  * [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://darcs.haskell.org/ 
+  * [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. 
+  * [http://www.cse.unsw.edu.au/~dons/code/hmp3/Core.hs hmp3], an curses mp3 player 
−  
−  [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://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=== 
=== Wiki examples=== 

Line 52:  Line 52:  
License ([[HaskellWiki:Copyrights]]). 
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. 
−  +  * [[Gallery]]: Complete small programs. 

−  [[ 
+  * [[Blow_your_mindBlow 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 [http://en.wikipedia.org/wiki/Sudoku Sudoku]. 

−  [[ 
+  * [[NewMonads]]: Useful monads that are not in the main library. 
−  +  * [[PrincipalVariationSearch]]: Principal variation search 

−  [ 
+  * [http://haskell.org/hawiki/ShootoutEntry Shootout Entries]: Examples still on the old wiki for the [http://shootout.alioth.debian.org/index.php The Computer Language Shootout Benchmarks]. 
−  
−  [[NewMonads]]: Useful monads that are not in the main library. 

−  
−  [[PrincipalVariationSearch]]: Principal variation search 

−  
−  [http://haskell.org/hawiki/ShootoutEntry Shootout Entries]: Examples still on the old wiki for the [http://shootout.alioth.debian.org/index.php The Computer Language Shootout Benchmarks]. 
Revision as of 08:00, 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 latexstyle Haskell)
 Dfa.lhs, finite automata (literate Birdstyle Haskell)
 RedBlackTree.hs, a redblack tree
 Prime.hs, prime numbers
 Foldable.hs, traversable data structures
 ByteString.hs, highperformance 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.