Example code: Difference between revisions
m (Fix broken links for Yi editor, Fix formatting for doc link) |
(→Examples: Redirected link to the Web Archive) |
||
(2 intermediate revisions by one other user not shown) | |||
Line 72: | Line 72: | ||
--> | --> | ||
* [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 ([https://archives.haskell.org/projects.haskell.org/cpphs/ home]) | ||
* [http://darcs.haskell.org/ghc/compiler/simplCore/Simplify.lhs GHC], a Haskell compiler (literate latex style) ([http://www.haskell.org/ghc/ home]) | * [http://darcs.haskell.org/ghc/compiler/simplCore/Simplify.lhs GHC], a Haskell compiler (literate latex style) ([http://www.haskell.org/ghc/ home]) | ||
Line 78: | Line 78: | ||
* [http://darcs.augustsson.net/Darcs/Djinn/Djinn/LJT.hs Djinn], a theorem prover ([http://darcs.augustsson.net/Darcs/Djinn/ home]) | * [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://code.haskell.org/c2hs/src/C2HS/C/Trav.hs c2hs], a C to Haskell interface generator ([https://github.com/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/lambdabot/LBState.hs Lambdabot], an IRC bot ([http://www.haskell.org/haskellwiki/Lambdabot home]) | ||
Line 90: | Line 90: | ||
; [[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). | ; [[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). | ||
; [ | ; [https://web.archive.org/web/20201109033750/members.chello.nl/hjgtuyl/tourdemonad.html A tour of the Haskell Monad functions]: Small usage examples of the basic Haskell monad functions | ||
[[Category:Code]] | [[Category:Code]] |
Latest revision as of 11:17, 22 October 2022
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.
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
- Data.Maybe, the
Maybe
type (docs)
- Data.Graph, a graph type (docs)
- Control.Monad, basic monad support (docs)
- QuickCheck, a testing framework (docs)
- PrettyPrint.hs, a pretty printing library (docs)
- Control.Monad.Trans.State.Lazy, a state monad (docs)
- Dfa.lhs, finite automata (literate Bird-style Haskell)
- RedBlackTree.hs, a red-black tree
- Data.Foldable, traversable data structures (docs)
- Data.ByteString, high-performance string type (raw, docs)
- SmallCheck, a testing framework (raw, docs)
Application code
Code from popular Haskell applications. Such code often makes use of a monadic IO, and sometimes other advanced features such as concurrency:
- hmp3, a curses mp3 player
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