Difference between revisions of "Example code"

From HaskellWiki
Jump to navigation Jump to search
(wibbles)
(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/Map.hs Map.hs], the standard finite map
+
* [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/Data/Tree.hs Tree.hs], a tree type
+
* [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/Data/Graph.hs Graph.hs], a graph type
+
* [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/packages/base/Control/Monad.hs Monad.hs], basic monadic support
+
* [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 (literate Bird-style Haskell)
 
[http://darcs.haskell.org/packages/QuickCheck/Test/QuickCheck.hs QuickCheck.hs], a testing framework
+
* [http://www.polyomino.f2s.com/david/haskell/hs/redblacktree.hs.txt RedBlackTree.hs], a red-black tree
 
* [http://andrew.bromage.org/darcs/numbertheory/Math/Prime.hs Prime.hs], prime numbers
 
[http://darcs.haskell.org/packages/base/Text/PrettyPrint/HughesPJ.hs PrettyPrint.hs], a pretty printing library
+
* [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], high-performance string type
 
[http://darcs.haskell.org/packages/monads/Monad/StateT.hs StateT.hs], a monad transformer library
+
* [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]
[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 (literate Bird-style Haskell)
 
 
[http://www.polyomino.f2s.com/david/haskell/hs/redblacktree.hs.txt RedBlackTree.hs], a red-black 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], high-performance 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 47: 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/darcs-unstable/PatchCommute.lhs Darcs], a revision control system (uses literate latex 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
+
* [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://www.cse.unsw.edu.au/~dons/code/yi/Yi/Core.hs Yi], a text editor
+
* [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 (literate latex style)
[http://j.mongers.org/pub/haskell/darcs/conjure/Conjure/Torrent.hs Conjure], a bittorrent client
 
 
* [http://www.augustsson.net/Darcs/Djinn/LJT.hs Djinn], a theorem prover
 
[http://darcs.haskell.org/~lemmih/downNova/src/Torrent.hs DownNova], a file downloading program
+
* [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.cs.york.ac.uk/fp/darcs/cpphs/Language/Preprocessor/Cpphs/Tokenise.hs cpphs], an implementation of the C preprocessor
+
* [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 78: 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_mind|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.
[[Gallery]]: Complete small programs.
 
 
* [[Sudoku]]: Solvers for popular puzzle [http://en.wikipedia.org/wiki/Sudoku Sudoku].
 
 
* [[NewMonads]]: Useful monads that are not in the main library.
[[Blow_your_mind|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.
 
 
* [[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].
[[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].
 

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:

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