-
Notifications
You must be signed in to change notification settings - Fork 100
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Create ReadTheDocs project for unordered-containers. #249
Open
m-renaud
wants to merge
10
commits into
haskell-unordered-containers:master
Choose a base branch
from
m-renaud:m-renaud-docs-user-guide
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
48767f7
Initial unordered-containers user guide content.
m-renaud c93a798
Address emilypi's review comments.
m-renaud 361fbf5
Fix incorrect HashMap.!? operator.
m-renaud dc030aa
Undo incorrect operator rename.
m-renaud fe4ffde
Remove use of (missing) HashMap.!?.
m-renaud 9e3ccdd
Add docs for newly added (since 0.2.11) HashMap.!?.
m-renaud 522fc41
DO NOT SUBMIT: Some partial conversion to Tutorial module.
m-renaud a331c1c
Formatting fixes in tutorial modules.
m-renaud 5e43fc1
More tutorial module content for comparison.
m-renaud 858da6a
Add Tutorial.HashMap module.
m-renaud File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[submodule "docs/_extensions/haddock-autolink"] | ||
path = docs/_extensions/haddock-autolink | ||
url = https://github.com/m-renaud/haddock-autolink |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
version: 2 | ||
|
||
sphinx: | ||
configuration: docs/conf.py | ||
|
||
submodules: | ||
include: | ||
- docs/_extensions/haddock-autolink | ||
|
||
python: | ||
version: 2.7 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
{-# OPTIONS_GHC -fno-warn-unused-imports #-} | ||
|
||
{-| | ||
The @unordered-containers@ package provides implementations of various | ||
hash-based immutable data structures. | ||
|
||
Some of the data structures provided by this package have a very large API | ||
surface (for better or worse). The docs here focus on the most common functions | ||
which should be more than enough to get you started. Once you know the basics, | ||
or if you're looking for a specific function, you can head over to the | ||
full API documentation! | ||
-} | ||
|
||
|
||
module Tutorial ( | ||
-- * Provided Data Structures | ||
-- $provideddatastructures | ||
|
||
-- * Related Packages | ||
-- $relatedpackages | ||
|
||
-- * Looking for more resources? | ||
-- $moreresources | ||
|
||
-- * Installing and using the @unordered-containers@ packages #installing# | ||
|
||
-- ** Version Requirements | ||
-- $versionreqs | ||
|
||
-- ** Importing modules | ||
-- $importingmodules | ||
|
||
-- ** In GHCi | ||
-- $ghci | ||
|
||
-- * HashSet and HashMap tutorial | ||
-- $tutorials | ||
|
||
) where | ||
|
||
{- $provideddatastructures | ||
* "Data.HashSet" - unordered, non-duplicated elements | ||
* '"Data.HashMap" - unordered map from keys to values (aka. dictionaries) | ||
-} | ||
|
||
{- $relatedpackages | ||
* <https://hackage.haskell.org/packages/containers containers> - ordered containers using trees instead of hashing. | ||
* <https://hackage.haskell.org/packages/hashable containers> - types that can be converted to a hash value. | ||
-} | ||
|
||
{- $moreresources | ||
If you've worked your way through the documentation here and you're looking for | ||
more examples or tutorials you should check out: | ||
|
||
* <https://haskell-lang.org/library/containers haskell-lang.org's containers tutorial>, its focused on the ordered | ||
<https://hackage.haskell.org/packages/containers containers> library but provides some useful examples. | ||
* <http://learnyouahaskell.com/modules Learn You a Haskell "Modules" chapter> | ||
-} | ||
|
||
{- $versionreqs | ||
All of the examples here should work for all recent versions of the package. | ||
-} | ||
|
||
{- $importingmodules | ||
|
||
All of the modules in @unordered-containers@@ should be imported @qualified@ | ||
since they use names that conflict with the standard Prelude. | ||
|
||
@ | ||
import qualified "Data.HashSet" as HashSet | ||
import qualified "Data.HashMap.Strict" as HashMap | ||
@ | ||
|
||
-} | ||
|
||
|
||
{- $ghci | ||
Start the GHCi | ||
<https://en.wikipedia.org/wiki/Read%E2%80%93eval%E2%80%93print_loop REPL> with | ||
@ghci@, @cabal repl@, or @stack ghci@. Once the REPL is loaded, import the | ||
modules you want using the @import@ statements above and you're good to go! | ||
-} | ||
|
||
|
||
{- $tutorials | ||
|
||
See "Tutorial.HashSet" and "Tutorial.HashMap". | ||
|
||
-} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{-# OPTIONS_GHC -fno-warn-unused-imports #-} | ||
|
||
{-| | ||
Sets allow you to store *unique* elements, providing efficient insertion, | ||
lookups, and deletions. If you are storing sets of @Int@ s consider using | ||
'Data.IntSet' from the <https://hackage.haskell.org/packages/containers containers> package. You can find the | ||
introductory documentation for @containers@ at | ||
<https://haskell-containers.readthedocs.io>. | ||
|
||
@ | ||
data HashMap k v = ... | ||
@ | ||
-} | ||
|
||
module Tutorial.HashMap () where |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,197 @@ | ||||||||||
{-# OPTIONS_GHC -fno-warn-unused-imports #-} | ||||||||||
|
||||||||||
{-| | ||||||||||
Sets allow you to store *unique* elements, providing efficient insertion, | ||||||||||
lookups, and deletions. If you are storing sets of @Int@ s consider using | ||||||||||
'Data.IntSet' from the <https://hackage.haskell.org/packages/containers containers> package. You can find the | ||||||||||
introductory documentation for @containers@ at | ||||||||||
<https://haskell-containers.readthedocs.io>. | ||||||||||
|
||||||||||
@ | ||||||||||
data 'HashSet' element = ... | ||||||||||
@ | ||||||||||
|
||||||||||
|
||||||||||
All of these implementations are /immutable/ which means that any update | ||||||||||
functions do not modify the set that you passed in, they creates a new set. In | ||||||||||
order to keep the changes you need to assign it to a new variable. For example: | ||||||||||
|
||||||||||
@ | ||||||||||
import qualified Data.HashSet as HashSet | ||||||||||
|
||||||||||
let s1 = HashSet.'HashSet.fromList' ["a", "b"] | ||||||||||
let s2 = HashSet.'HashSet.delete' "a" s1 | ||||||||||
print s1 | ||||||||||
> HashSet.'HashSet.fromList' ["a","b"] | ||||||||||
print s2 | ||||||||||
> HashSet.'HashSet.fromList' ["b"] | ||||||||||
@ | ||||||||||
|
||||||||||
__IMPORTANT:__ @HashSet@ relies on the @element@ type having instances of the @Eq@ and | ||||||||||
@Hashable@ typeclasses for its internal representation. These are already | ||||||||||
defined for builtin types, and if you are using your own data type you can | ||||||||||
use the | ||||||||||
<https://en.wikibooks.org/wiki/Haskell/Classes_and_types#Deriving deriving> | ||||||||||
mechanism. | ||||||||||
|
||||||||||
|
||||||||||
-} | ||||||||||
|
||||||||||
module Tutorial.HashSet ( | ||||||||||
-- * Short Example | ||||||||||
-- $shortexample | ||||||||||
|
||||||||||
-- * Importing HashSet | ||||||||||
-- $importing | ||||||||||
|
||||||||||
-- * Common API Functions | ||||||||||
-- ** Construction and Conversion | ||||||||||
|
||||||||||
-- *** Create an empty set | ||||||||||
-- $empty | ||||||||||
|
||||||||||
-- *** Create a set with one element (singleton) | ||||||||||
-- $singleton | ||||||||||
|
||||||||||
-- *** Create a set from a list | ||||||||||
-- $fromlist | ||||||||||
|
||||||||||
-- * Continue reading | ||||||||||
-- $continuereading | ||||||||||
) where | ||||||||||
|
||||||||||
import qualified Data.HashSet as HashSet | ||||||||||
|
||||||||||
{- $shortexample | ||||||||||
|
||||||||||
The following GHCi session shows some of the basic set functionality: | ||||||||||
|
||||||||||
@ | ||||||||||
import qualified Data.HashSet as HashSet | ||||||||||
|
||||||||||
let dataStructures = HashSet.'HashSet.fromList' [\"HashSet\", \"HashMap\", \"Graph\"] | ||||||||||
|
||||||||||
-- Check if HashMap and Trie are in the set of data structures. | ||||||||||
HashSet.'HashSet.member' \"HashMap\" dataStructures | ||||||||||
> True | ||||||||||
|
||||||||||
HashSet.'HashSet.member' "Trie" dataStructures | ||||||||||
> False | ||||||||||
|
||||||||||
|
||||||||||
-- Add Trie to our original set of data structures. | ||||||||||
let moreDataStructures = HashSet.'HashSet.insert' \"Trie\" dataStructures | ||||||||||
|
||||||||||
HashSet.'HashSet.member' \"Trie\" moreDataStructures | ||||||||||
> True | ||||||||||
|
||||||||||
|
||||||||||
-- Remove Graph from our original set of data structures. | ||||||||||
let fewerDataStructures = HashSet.'HashSet.delete' \"Graph\" dataStructures | ||||||||||
|
||||||||||
HashSet.'HashSet.toList' fewerDataStructures | ||||||||||
> [\"HashSet\", \"HashMap\"] | ||||||||||
|
||||||||||
|
||||||||||
-- Create a new set and combine it with our original set. | ||||||||||
let orderedDataStructures = HashSet.'HashSet.fromList' [\"Set\", \"Map\"] | ||||||||||
|
||||||||||
HashSet.'HashSet.union' dataStructures orderedDataStructures | ||||||||||
> fromList [\"Map\", \"HashSet\", \"Graph\", \"HashMap\", \"Set\"] | ||||||||||
@ | ||||||||||
|
||||||||||
|
||||||||||
__TIP__: You can use the | ||||||||||
<https://ghc.haskell.org/trac/ghc/wiki/OverloadedLists OverloadedLists> | ||||||||||
extension so you don't need to write `fromList [1, 2, 3]` everywhere. | ||||||||||
Instead you can just write `[1, 2, 3]` and if the function is expecting | ||||||||||
a set it will be converted automatically! The code here will continue | ||||||||||
to use `fromList` for clarity though. | ||||||||||
|
||||||||||
|
||||||||||
-} | ||||||||||
|
||||||||||
|
||||||||||
{- $importing | ||||||||||
|
||||||||||
When using HashSet in a Haskell source file you should always use a `qualified` | ||||||||||
import because these modules export names that clash with the standard Prelude. | ||||||||||
You can import the type constructor unqualified. | ||||||||||
|
||||||||||
@ | ||||||||||
import Data.HashSet (HashSet) | ||||||||||
import qualified Data.HashSet as HashSet | ||||||||||
@ | ||||||||||
|
||||||||||
-} | ||||||||||
|
||||||||||
{- $commonapifunctions | ||||||||||
|
||||||||||
|
||||||||||
.. TIP:: | ||||||||||
All of these functions that work for `HashSet` will also work for | ||||||||||
`IntSet`, which has the element type `a` specialized to `Int`. Anywhere | ||||||||||
that you see `HashSet Int` you can replace it with `IntSet`. This will | ||||||||||
speed up most operations tremendously (see `Performance`_) with the exception | ||||||||||
of `size` which is O(1) for `HashSet` and O(n) for `IntSet`. | ||||||||||
|
||||||||||
.. NOTE:: | ||||||||||
`fromList [some,list,elements]` is how a `HashSet` is printed. | ||||||||||
|
||||||||||
-} | ||||||||||
|
||||||||||
{- $empty | ||||||||||
@ | ||||||||||
HashSet.empty :: HashSet a | ||||||||||
HashSet.empty = ... | ||||||||||
@ | ||||||||||
|
||||||||||
`HashSet.empty' creates a set with zero elements. | ||||||||||
|
||||||||||
@ | ||||||||||
HashSet.empty | ||||||||||
> fromList [] | ||||||||||
@ | ||||||||||
|
||||||||||
-} | ||||||||||
|
||||||||||
{- $singleton | ||||||||||
@ | ||||||||||
HashSet.singleton :: a -> HashSet a | ||||||||||
HashSet.singleton x = ... | ||||||||||
@ | ||||||||||
|
||||||||||
'HashSet.singleton' creates a set with a single element | ||||||||||
`x` in it. | ||||||||||
|
||||||||||
@ | ||||||||||
HashSet.singleton "containers" | ||||||||||
> fromList ["containers"] | ||||||||||
|
||||||||||
HashSet.singleton 1 | ||||||||||
> fromList [1] | ||||||||||
@ | ||||||||||
-} | ||||||||||
|
||||||||||
{- $fromlist | ||||||||||
@ | ||||||||||
HashSet.fromList :: [a] -> HashSet a | ||||||||||
HashSet.fromList xs = ... | ||||||||||
@ | ||||||||||
|
||||||||||
'HashSet.fromList' creates a set containing the elements of the | ||||||||||
list `xs`. Since sets don't contain duplicates, if there are repeated elements | ||||||||||
in the list they will only appear once. | ||||||||||
|
||||||||||
@ | ||||||||||
HashSet.fromList ["base", "containers", "QuickCheck"] | ||||||||||
> fromList [,"containers","base","QuickCheck"] | ||||||||||
Comment on lines
+187
to
+188
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
|
||||||||||
HashSet.fromList [1, 1, 2, 3, 4, 4, 5, 1] | ||||||||||
> fromList [1,2,3,4,5] | ||||||||||
@ | ||||||||||
-} | ||||||||||
|
||||||||||
{- $continuereading | ||||||||||
Continue the tutorial at "Tutorial.HashMap". | ||||||||||
-} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# Minimal makefile for Sphinx documentation | ||
# | ||
|
||
# You can set these variables from the command line. | ||
SPHINXOPTS = -a -E | ||
SPHINXBUILD = sphinx-build | ||
SPHINXPROJ = unordered-containers | ||
SOURCEDIR = . | ||
BUILDDIR = _build | ||
|
||
# Put it first so that "make" without argument is like "make help". | ||
help: | ||
@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) | ||
|
||
.PHONY: help Makefile | ||
|
||
# Catch-all target: route all unknown targets to Sphinx using the new | ||
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS). | ||
%: Makefile | ||
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) |
Submodule haddock-autolink
added at
51c39a
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
def setup(app): | ||
app.add_stylesheet('css/hs-theme.css') |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
.wy-side-nav-search { | ||
background-color: #222 !important; | ||
} | ||
|
||
.wy-nav-top { | ||
background-color: #333 !important; | ||
} | ||
|
||
.wy-nav-top i { | ||
color: #282 !important; | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This style seems rather unusual and also doesn't fit with the way most GHCi sessions look. The usual
doctest
-style seems clearer to me: