Example code
From HaskellWiki
(Difference between revisions)
(→Library code) |
m (→Application code) |
||
| (32 intermediate revisions not shown.) | |||
| 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. | + | examples from various popular [[Libraries_and_tools|Haskell projects]]. |
| - | + | To start learning the language, good places to start are | |
| - | [[ | + | [[Learning Haskell]], |
| + | [[Haskell in 5 steps]], and | ||
| + | [[Books and tutorials]]. | ||
| + | |||
| + | More code may be found [http://www.haskell.org/haskellwiki/Category:Code on the wiki]. | ||
| + | |||
| + | <!-- | ||
| + | Some lines are commented out for later update | ||
| + | --> | ||
=== Library code === | === Library code === | ||
Library code usually differs from application code: it is often highly | Library code usually differs from application code: it is often highly | ||
| - | structured, and documented with [http://haskell.org/haddock haddock], | + | structured, and documented with [http://www.haskell.org/haddock/ haddock], |
and can be rather optimised. Some instructive examples (syntax | and can be rather optimised. Some instructive examples (syntax | ||
highlighting by [http://www.cs.york.ac.uk/fp/darcs/hscolour/ hscolour]): | highlighting by [http://www.cs.york.ac.uk/fp/darcs/hscolour/ hscolour]): | ||
| - | * [http://www. | + | * [http://www.haskell.org/ghc/docs/latest/html/libraries/base/src/Prelude.html A Haskell Prelude.hs], foundational Haskell library ([http://www.haskell.org/ghc/docs/latest/html/libraries/base/Prelude.html docs]) |
| - | * [http:// | + | |
| - | * [http:// | + | * [[Simple_Unix_tools | Unix.hs]], simple unix tools, for beginner Haskellers |
| - | * [http:// | + | |
| - | * [http:// | + | * [http://hackage.haskell.org/packages/archive/base/latest/doc/html/src/Data-List.html List.hs], the standard list library ([http://hackage.haskell.org/packages/archive/base/latest/doc/html/Data-List.html docs]) |
| - | * [http:// | + | |
| - | * [http:// | + | * [http://hackage.haskell.org/packages/archive/base/latest/doc/html/src/Data-Maybe.html Maybe.hs], the <code>Maybe</code> type ([http://hackage.haskell.org/packages/archive/base/latest/doc/html/Data-Maybe.html docs]) |
| - | * [http:// | + | |
| - | * [http:// | + | * [http://hackage.haskell.org/packages/archive/containers/latest/doc/html/src/Data-Map.html Map.hs], the standard finite map ([http://www.haskell.org/ghc/docs/latest/html/libraries/containers-0.4.2.1/index.html docs]) |
| - | * [http://www.cse.unsw.edu.au/~dons/data/Music.html Music.hs], a music composition system (literate latex-style Haskell) ([http://darcs.haskell.org/haskore/src/Haskore/Music.lhs raw]) | + | |
| + | * [http://hackage.haskell.org/packages/archive/containers/latest/doc/html/src/Data-Graph.html Graph.hs], a graph type ([http://hackage.haskell.org/packages/archive/containers/latest/doc/html/Data-Graph.html docs]) | ||
| + | |||
| + | * [http://hackage.haskell.org/packages/archive/base/latest/doc/html/src/Control-Monad.html Monad.hs], basic monad support ([http://hackage.haskell.org/packages/archive/base/latest/doc/html/Control-Monad.html docs]) | ||
| + | |||
| + | * [http://code.haskell.org/QuickCheck/stable/Test/QuickCheck/ QuickCheck], a testing framework ([http://hackage.haskell.org/package/QuickCheck docs]) | ||
| + | |||
| + | * [http://hackage.haskell.org/packages/archive/pretty/latest/doc/html/src/Text-PrettyPrint-HughesPJ.html PrettyPrint.hs], a pretty printing library ([http://hackage.haskell.org/package/pretty docs]) | ||
| + | |||
| + | * [http://hackage.haskell.org/packages/archive/transformers/latest/doc/html/src/Control-Monad-Trans-State-Lazy.html State.hs], a state monad ([http://hackage.haskell.org/packages/archive/transformers/latest/doc/html/Control-Monad-Trans-State-Lazy.html docs]) | ||
| + | <!-- | ||
| + | * [http://www.cse.unsw.edu.au/~dons/data/Music.html Music.hs], a music composition system (literate latex-style Haskell) ([http://darcs.haskell.org/haskore/src/Haskore/Music.lhs raw], [http://www.haskell.org/haskore/ home]) | ||
| + | --> | ||
| + | |||
* [http://www.ninebynine.org/Software/Swish-0.2.1/HaskellRDF/Dfa/Dfa.lhs Dfa.lhs], finite automata (literate Bird-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. | + | |
| - | + | * [http://www.polyomino.f2s.com/david/haskell/hs/RedBlackTree.hs.txt RedBlackTree.hs], a red-black tree | |
| - | * [http:// | + | <!-- |
| - | * [http://www. | + | * [http://www.cse.unsw.edu.au/~dons/data/Prime.html Prime.hs], prime numbers ([http://andrew.bromage.org/darcs/numbertheory/Math/Prime.hs raw]) |
| - | + | --> | |
| - | + | ||
| - | * [http://haskell.org/haskellwiki/Darcs_repositories More code ...] | + | * [http://hackage.haskell.org/packages/archive/base/latest/doc/html/src/Data-Foldable.html Foldable.hs], traversable data structures ([http://hackage.haskell.org/packages/archive/base/latest/doc/html/Data-Foldable.html docs]) |
| + | |||
| + | * [http://www.haskell.org/ghc/docs/latest/html/libraries/bytestring/src/Data-ByteString.html ByteString.hs], high-performance string type ([http://code.haskell.org/bytestring/Data/ByteString.hs raw], [http://hackage.haskell.org/package/bytestring docs]) | ||
| + | |||
| + | * [https://github.com/feuerbach/smallcheck/blob/master/Test/SmallCheck.hs SmallCheck.hs], a testing framework ([https://raw.github.com/feuerbach/smallcheck/master/Test/SmallCheck.hs raw], [http://hackage.haskell.org/package/smallcheck docs]) | ||
| + | |||
| + | * [http://www.haskell.org/haskellwiki/Darcs_repositories More code ...] | ||
=== Application code === | === Application code === | ||
| Line 35: | Line 62: | ||
monadic IO, and sometimes other advanced features such as concurrency: | monadic IO, and sometimes other advanced features such as concurrency: | ||
| - | * [http:// | + | <!-- |
| - | * [http://svn.openfoundry.org/pugs/src/Pugs/Eval.hs Pugs], a perl6 implementation | + | * [http://nanardon.zarb.org/darcs/darcs/PatchCommute.lhs Darcs], a revision control system (uses literate latex Haskell style) ([http://darcs.net home]) |
| - | + | --> | |
| - | + | * [http://svn.openfoundry.org/pugs/src/Pugs/Eval.hs Pugs], a perl6 implementation ([http://pugscode.org home]) | |
| + | |||
| + | * [https://github.com/yi-editor/yi/blob/master/yi/src/library/Yi/Core.hs Yi], a text editor, ([http://www.haskell.org/haskellwiki/Yi home], [https://raw.github.com/yi-editor/yi/master/yi/src/library/Yi/Core.hs raw, [http://hackage.haskell.org/package/yi doc]) | ||
| + | <!-- | ||
* [http://darcs.haskell.org/~lemmih/downNova/src/Torrent.hs DownNova], a file downloading program | * [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:// | + | * [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/cpphs/ home]) |
| - | * [http:// | + | |
| - | + | * [http://darcs.haskell.org/ghc/compiler/simplCore/Simplify.lhs GHC], a Haskell compiler (literate latex style) ([http://www.haskell.org/ghc/ home]) | |
| - | + | ||
| - | * [http://haskell.org/haskellwiki/Darcs_repositories More code ...] | + | * [http://darcs.augustsson.net/Darcs/Djinn/Djinn/LJT.hs Djinn], a theorem prover ([http://darcs.augustsson.net/Darcs/Djinn/ home]) |
| + | |||
| + | * [http://code.haskell.org/c2hs/src/C2HS/C/Trav.hs c2hs], a C to Haskell interface generator ([http://www.cse.unsw.edu.au/~chak/haskell/c2hs/ home]) | ||
| + | |||
| + | * [http://code.haskell.org/lambdabot/LBState.hs Lambdabot], an IRC bot ([http://www.haskell.org/haskellwiki/Lambdabot home]) | ||
| + | |||
| + | * [http://code.haskell.org/~dons/code/hmp3/Core.hs hmp3], a curses mp3 player | ||
| + | |||
| + | * [http://www.haskell.org/haskellwiki/Darcs_repositories More code ...] | ||
| - | == | + | == Examples == |
| - | + | ; [[Tying the Knot]] : An example that illustrates different ways to define recursive data structures. The example defines a simple language (illustrating how to define some recursive structures) and an interpreter for the language (illustrating how to work with the recursive structures). | |
| - | [ | + | |
| - | + | ||
| - | + | ||
| - | + | ||
| - | + | ||
| - | + | ; [http://members.chello.nl/hjgtuyl/tourdemonad.html A tour of the Haskell Monad functions]: Small usage examples of the basic Haskell monad functions | |
| - | + | [[Category:Code]] | |
| - | + | ||
| - | + | ||
| - | + | ||
| - | + | ||
| - | + | ||
| - | + | ||
| - | + | ||
Current revision
To get a feel for what real world Haskell looks like, here are some examples from various popular Haskell projects. To start learning the language, good places to start are Learning Haskell, Haskell in 5 steps, and Books and tutorials.
More code may be found on the wiki.
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 (syntax highlighting by hscolour):
- A Haskell Prelude.hs, foundational Haskell library (docs)
- Unix.hs, simple unix tools, for beginner Haskellers
- QuickCheck, a testing framework (docs)
- PrettyPrint.hs, a pretty printing library (docs)
- Dfa.lhs, finite automata (literate Bird-style Haskell)
- RedBlackTree.hs, a red-black tree
- Foldable.hs, traversable data structures (docs)
- ByteString.hs, high-performance string type (raw, docs)
- SmallCheck.hs, a testing framework (raw, docs)
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:
- Yi, a text editor, (home, raw, [http://hackage.haskell.org/package/yi doc)
- hmp3, a curses mp3 player
3 Examples
- Tying the Knot
- An example that illustrates different ways to define recursive data structures. The example defines a simple language (illustrating how to define some recursive structures) and an interpreter for the language (illustrating how to work with the recursive structures).
- A tour of the Haskell Monad functions
- Small usage examples of the basic Haskell monad functions
