From 60ca33fecb6a8b292a45fdfa16b62c4bc0479154 Mon Sep 17 00:00:00 2001 From: Stephen Diehl Date: Thu, 8 Dec 2016 09:36:00 +0000 Subject: [PATCH 01/24] begin conversion to rst --- docs/{Applicative.md => Applicative.rst} | 0 docs/{Exceptions.md => Exceptions.rst} | 0 docs/Function.md | 50 ---- docs/Function.rst | 83 ++++++ docs/Index.md | 32 --- docs/{List.md => List.rst} | 0 docs/{Monad.md => Monad.rst} | 0 docs/Tuple.md | 22 -- docs/Tuple.rst | 84 ++++++ docs/{TypeLevel.md => TypeLevel.rst} | 0 docs/conf.py | 340 +++++++++++++++++++++++ docs/index.rst | 44 +++ 12 files changed, 551 insertions(+), 104 deletions(-) rename docs/{Applicative.md => Applicative.rst} (100%) rename docs/{Exceptions.md => Exceptions.rst} (100%) delete mode 100644 docs/Function.md create mode 100644 docs/Function.rst delete mode 100644 docs/Index.md rename docs/{List.md => List.rst} (100%) rename docs/{Monad.md => Monad.rst} (100%) delete mode 100644 docs/Tuple.md create mode 100644 docs/Tuple.rst rename docs/{TypeLevel.md => TypeLevel.rst} (100%) create mode 100644 docs/conf.py create mode 100644 docs/index.rst diff --git a/docs/Applicative.md b/docs/Applicative.rst similarity index 100% rename from docs/Applicative.md rename to docs/Applicative.rst diff --git a/docs/Exceptions.md b/docs/Exceptions.rst similarity index 100% rename from docs/Exceptions.md rename to docs/Exceptions.rst diff --git a/docs/Function.md b/docs/Function.md deleted file mode 100644 index a8f23e8cd..000000000 --- a/docs/Function.md +++ /dev/null @@ -1,50 +0,0 @@ -Functions -========= - -```haskell -($) :: (a -> b) -> a -> b -``` - -```haskell -(&) :: a -> (a -> b) -> b -``` - -```haskell -(.) :: (b -> c) -> (a -> b) -> a -> c -``` - -```haskell -flip :: (a -> b -> c) -> b -> a -> c -``` - -```haskell -on :: (b -> b -> c) -> (a -> b) -> a -> a -> c -``` - -```haskell -const :: a -> b -> a -``` - -```haskell -fix :: (a -> a) -> a -``` - -```haskell -($!) :: (a -> b) -> a -> b -``` - -```haskell -identity :: a -> a -``` - -```haskell -($!!) :: NFData a => (a -> b) -> a -> b -``` - -```haskell -($!!) :: NFData a => (a -> b) -> a -> b -``` - -```haskell -force :: NFData a => a -> a -``` diff --git a/docs/Function.rst b/docs/Function.rst new file mode 100644 index 000000000..2f5f1ed70 --- /dev/null +++ b/docs/Function.rst @@ -0,0 +1,83 @@ +Functions +========= + +.. highlight:: haskell + +$ +*** + +:: + + ($) :: (a -> b) -> a -> b + +& +*** + +:: + + (&) :: a -> (a -> b) -> b + +. +*** + +:: + + (.) :: (b -> c) -> (a -> b) -> a -> c + + +flip +**** + +:: + + flip :: (a -> b -> c) -> b -> a -> c + + +on +*** + +:: + + on :: (b -> b -> c) -> (a -> b) -> a -> a -> c + +const +***** + +:: + + const :: a -> b -> a + +fix +*** + +:: + + fix :: (a -> a) -> a + +identity +******** + +:: + + identity :: a -> a + +$! +*** + +:: + + ($!) :: NFData a => (a -> b) -> a -> b + +$!! +*** + +:: + + ($!!) :: NFData a => (a -> b) -> a -> b + +force +***** + +:: + + force :: NFData a => a -> a diff --git a/docs/Index.md b/docs/Index.md deleted file mode 100644 index 1b1b3dab7..000000000 --- a/docs/Index.md +++ /dev/null @@ -1,32 +0,0 @@ -Welcome to project documentation. - -- [Printing](Printing.md) -- [File Handling](Files.md) -- [Strings](Strings.md) -- [Functions](Function.md) -- [Functors](Applicative.md) -- [Monad](Monad.md) -- [Maybe](Maybe.md) -- [Either](Either.md) -- [Booleans](Bool.md) -- [Numbers](Numbers.md) -- [Monoid](Monoid.md) -- [Semigroup](Semigroup.md) -- [Bifunctor](Bifunctor.md) -- [Lists](List.md) -- [Folds](Folds.md) -- [Traversals](Traversals.md) -- [Transformers](Transformers.md) -- [Reader](Reader.md) -- [State](State.md) -- [Exception Handling](Exceptions.md) -- [ST](ST.md) -- [Async & Concurrency](Concurrency.md) -- [Storable & Bytes](Storable.md) -- [System](Systsem.md) -- [Dictionaries](Map.md) -- [Sets](Set.md) -- [Tuples](Tuples.md) -- [Generics](Generics.md) -- [Type Level Programming](TypeLevel.md) -- [Unsafe](Unsafe.md) diff --git a/docs/List.md b/docs/List.rst similarity index 100% rename from docs/List.md rename to docs/List.rst diff --git a/docs/Monad.md b/docs/Monad.rst similarity index 100% rename from docs/Monad.md rename to docs/Monad.rst diff --git a/docs/Tuple.md b/docs/Tuple.md deleted file mode 100644 index 3b59ad459..000000000 --- a/docs/Tuple.md +++ /dev/null @@ -1,22 +0,0 @@ -Tuples -====== - -```haskell -fst :: (a, b) -> a -``` - -```haskell -snd :: (a, b) -> b -``` - -```haskell -swap :: (a, b) -> (b, a) -``` - -```haskell -curry :: ((a, b) -> c) -> a -> b -> c -``` - -```haskell -uncurry :: (a -> b -> c) -> (a, b) -> c -``` diff --git a/docs/Tuple.rst b/docs/Tuple.rst new file mode 100644 index 000000000..5ce5679d2 --- /dev/null +++ b/docs/Tuple.rst @@ -0,0 +1,84 @@ +Tuples +====== + +.. highlight:: haskell + +fst +*** + +:: + + fst :: (a, b) -> a + +Extract the first component of a pair. + +*Example*: + +:: + + > fst (1,2) + 1 + +snd +*** + +:: + + snd :: (a, b) -> b + +Extract the second component of a pair. + +*Example*: + +:: + + > snd (1,2) + 2 + +swap +**** + +:: + + swap :: (a, b) -> (b, a) + +Swap the components of a pair. + +*Example*: + +:: + + > swap (1,2) + (2,1) + +curry +***** + +:: + + curry :: ((a, b) -> c) -> a -> b -> c + +curry converts an uncurried function to a curried function. + +*Example*: + +:: + + > curry fst 1 2 + 1 + +uncurry +******* + +:: + + uncurry :: (a -> b -> c) -> (a, b) -> c + +uncurry converts a curried function to a function on pairs. + +*Example*: + +:: + + > uncurry (+) (1,2) + 3 diff --git a/docs/TypeLevel.md b/docs/TypeLevel.rst similarity index 100% rename from docs/TypeLevel.md rename to docs/TypeLevel.rst diff --git a/docs/conf.py b/docs/conf.py new file mode 100644 index 000000000..2b8a07eaf --- /dev/null +++ b/docs/conf.py @@ -0,0 +1,340 @@ +# -*- coding: utf-8 -*- +# +# protolude documentation build configuration file, created by +# sphinx-quickstart on Thu Dec 8 09:08:30 2016. +# +# This file is execfile()d with the current directory set to its +# containing dir. +# +# Note that not all possible configuration values are present in this +# autogenerated file. +# +# All configuration values have a default; values that are commented out +# serve to show the default. + +# If extensions (or modules to document with autodoc) are in another directory, +# add these directories to sys.path here. If the directory is relative to the +# documentation root, use os.path.abspath to make it absolute, like shown here. +# +# import os +# import sys +# sys.path.insert(0, os.path.abspath('.')) + +# -- General configuration ------------------------------------------------ + +# If your documentation needs a minimal Sphinx version, state it here. +# +# needs_sphinx = '1.0' + +# Add any Sphinx extension module names here, as strings. They can be +# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom +# ones. +extensions = [ + 'sphinx.ext.githubpages', +] + +# Add any paths that contain templates here, relative to this directory. +templates_path = ['_templates'] + +# The suffix(es) of source filenames. +# You can specify multiple suffix as a list of string: +# +# source_suffix = ['.rst', '.md'] +source_suffix = '.rst' + +# The encoding of source files. +# +# source_encoding = 'utf-8-sig' + +# The master toctree document. +master_doc = 'index' + +# General information about the project. +project = u'protolude' +copyright = u'2016, Stephen Diehl' +author = u'Stephen Diehl' + +# The version info for the project you're documenting, acts as replacement for +# |version| and |release|, also used in various other places throughout the +# built documents. +# +# The short X.Y version. +version = u'0.1.11' +# The full version, including alpha/beta/rc tags. +release = u'0.1.11' + +# The language for content autogenerated by Sphinx. Refer to documentation +# for a list of supported languages. +# +# This is also used if you do content translation via gettext catalogs. +# Usually you set "language" from the command line for these cases. +language = None + +# There are two options for replacing |today|: either, you set today to some +# non-false value, then it is used: +# +# today = '' +# +# Else, today_fmt is used as the format for a strftime call. +# +# today_fmt = '%B %d, %Y' + +# List of patterns, relative to source directory, that match files and +# directories to ignore when looking for source files. +# This patterns also effect to html_static_path and html_extra_path +exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store'] + +# The reST default role (used for this markup: `text`) to use for all +# documents. +# +# default_role = None + +# If true, '()' will be appended to :func: etc. cross-reference text. +# +# add_function_parentheses = True + +# If true, the current module name will be prepended to all description +# unit titles (such as .. function::). +# +# add_module_names = True + +# If true, sectionauthor and moduleauthor directives will be shown in the +# output. They are ignored by default. +# +# show_authors = False + +# The name of the Pygments (syntax highlighting) style to use. +pygments_style = 'sphinx' + +# A list of ignored prefixes for module index sorting. +# modindex_common_prefix = [] + +# If true, keep warnings as "system message" paragraphs in the built documents. +# keep_warnings = False + +# If true, `todo` and `todoList` produce output, else they produce nothing. +todo_include_todos = False + + +# -- Options for HTML output ---------------------------------------------- + +# The theme to use for HTML and HTML Help pages. See the documentation for +# a list of builtin themes. +# +html_theme = 'alabaster' + +# Theme options are theme-specific and customize the look and feel of a theme +# further. For a list of options available for each theme, see the +# documentation. +# +# html_theme_options = {} + +# Add any paths that contain custom themes here, relative to this directory. +# html_theme_path = [] + +# The name for this set of Sphinx documents. +# " v documentation" by default. +# +# html_title = u'protolude v0.1.11' + +# A shorter title for the navigation bar. Default is the same as html_title. +# +# html_short_title = None + +# The name of an image file (relative to this directory) to place at the top +# of the sidebar. +# +# html_logo = None + +# The name of an image file (relative to this directory) to use as a favicon of +# the docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32 +# pixels large. +# +# html_favicon = None + +# Add any paths that contain custom static files (such as style sheets) here, +# relative to this directory. They are copied after the builtin static files, +# so a file named "default.css" will overwrite the builtin "default.css". +html_static_path = ['_static'] + +# Add any extra paths that contain custom files (such as robots.txt or +# .htaccess) here, relative to this directory. These files are copied +# directly to the root of the documentation. +# +# html_extra_path = [] + +# If not None, a 'Last updated on:' timestamp is inserted at every page +# bottom, using the given strftime format. +# The empty string is equivalent to '%b %d, %Y'. +# +# html_last_updated_fmt = None + +# If true, SmartyPants will be used to convert quotes and dashes to +# typographically correct entities. +# +# html_use_smartypants = True + +# Custom sidebar templates, maps document names to template names. +# +# html_sidebars = {} + +# Additional templates that should be rendered to pages, maps page names to +# template names. +# +# html_additional_pages = {} + +# If false, no module index is generated. +# +# html_domain_indices = True + +# If false, no index is generated. +# +# html_use_index = True + +# If true, the index is split into individual pages for each letter. +# +# html_split_index = False + +# If true, links to the reST sources are added to the pages. +# +# html_show_sourcelink = True + +# If true, "Created using Sphinx" is shown in the HTML footer. Default is True. +# +# html_show_sphinx = True + +# If true, "(C) Copyright ..." is shown in the HTML footer. Default is True. +# +# html_show_copyright = True + +# If true, an OpenSearch description file will be output, and all pages will +# contain a tag referring to it. The value of this option must be the +# base URL from which the finished HTML is served. +# +# html_use_opensearch = '' + +# This is the file name suffix for HTML files (e.g. ".xhtml"). +# html_file_suffix = None + +# Language to be used for generating the HTML full-text search index. +# Sphinx supports the following languages: +# 'da', 'de', 'en', 'es', 'fi', 'fr', 'hu', 'it', 'ja' +# 'nl', 'no', 'pt', 'ro', 'ru', 'sv', 'tr', 'zh' +# +# html_search_language = 'en' + +# A dictionary with options for the search language support, empty by default. +# 'ja' uses this config value. +# 'zh' user can custom change `jieba` dictionary path. +# +# html_search_options = {'type': 'default'} + +# The name of a javascript file (relative to the configuration directory) that +# implements a search results scorer. If empty, the default will be used. +# +# html_search_scorer = 'scorer.js' + +# Output file base name for HTML help builder. +htmlhelp_basename = 'protoludedoc' + +# -- Options for LaTeX output --------------------------------------------- + +latex_elements = { + # The paper size ('letterpaper' or 'a4paper'). + # + # 'papersize': 'letterpaper', + + # The font size ('10pt', '11pt' or '12pt'). + # + # 'pointsize': '10pt', + + # Additional stuff for the LaTeX preamble. + # + # 'preamble': '', + + # Latex figure (float) alignment + # + # 'figure_align': 'htbp', +} + +# Grouping the document tree into LaTeX files. List of tuples +# (source start file, target name, title, +# author, documentclass [howto, manual, or own class]). +latex_documents = [ + (master_doc, 'protolude.tex', u'protolude Documentation', + u'Stephen Diehl', 'manual'), +] + +# The name of an image file (relative to this directory) to place at the top of +# the title page. +# +# latex_logo = None + +# For "manual" documents, if this is true, then toplevel headings are parts, +# not chapters. +# +# latex_use_parts = False + +# If true, show page references after internal links. +# +# latex_show_pagerefs = False + +# If true, show URL addresses after external links. +# +# latex_show_urls = False + +# Documents to append as an appendix to all manuals. +# +# latex_appendices = [] + +# It false, will not define \strong, \code, itleref, \crossref ... but only +# \sphinxstrong, ..., \sphinxtitleref, ... To help avoid clash with user added +# packages. +# +# latex_keep_old_macro_names = True + +# If false, no module index is generated. +# +# latex_domain_indices = True + + +# -- Options for manual page output --------------------------------------- + +# One entry per manual page. List of tuples +# (source start file, name, description, authors, manual section). +man_pages = [ + (master_doc, 'protolude', u'protolude Documentation', + [author], 1) +] + +# If true, show URL addresses after external links. +# +# man_show_urls = False + + +# -- Options for Texinfo output ------------------------------------------- + +# Grouping the document tree into Texinfo files. List of tuples +# (source start file, target name, title, author, +# dir menu entry, description, category) +texinfo_documents = [ + (master_doc, 'protolude', u'protolude Documentation', + author, 'protolude', 'One line description of project.', + 'Miscellaneous'), +] + +# Documents to append as an appendix to all manuals. +# +# texinfo_appendices = [] + +# If false, no module index is generated. +# +# texinfo_domain_indices = True + +# How to display URL addresses: 'footnote', 'no', or 'inline'. +# +# texinfo_show_urls = 'footnote' + +# If true, do not generate a @detailmenu in the "Top" node's menu. +# +# texinfo_no_detailmenu = False diff --git a/docs/index.rst b/docs/index.rst new file mode 100644 index 000000000..127aba249 --- /dev/null +++ b/docs/index.rst @@ -0,0 +1,44 @@ +Protolude Documentation +======================= + +An alternative Prelude. + +.. toctree:: + :maxdepth: 1 + Printing + Files + Strings + Function + Applicative + Monad + Maybe + Either + Bool + Numbers + Monoid + Semigroup + Bifunctor + List + Folds + Traversals + Transformers + Reader + State + Exceptions + ST + Concurrency + Storable + Systsem + Map + Set + Tuple + Generics + TypeLevel + Unsafe + +Indices and tables +================== + +* :ref:`genindex` +* :ref:`modindex` +* :ref:`search` From ca74e2901d52ab934f5b042a12d61d8477704cb0 Mon Sep 17 00:00:00 2001 From: Stephen Diehl Date: Thu, 8 Dec 2016 09:47:06 +0000 Subject: [PATCH 02/24] document structure --- docs/Applicative.rst | 9 ++++++--- docs/Bool.rst | 2 ++ docs/Either.rst | 2 ++ docs/Folds.rst | 2 ++ docs/List.rst | 21 ++++++++++++++------- docs/Maybe.rst | 2 ++ docs/Monad.rst | 6 ++++-- docs/Monoid.rst | 2 ++ docs/Numbers.rst | 2 ++ docs/Strings.rst | 14 ++++++++++++++ docs/index.rst | 4 ++-- 11 files changed, 52 insertions(+), 14 deletions(-) create mode 100644 docs/Bool.rst create mode 100644 docs/Either.rst create mode 100644 docs/Folds.rst create mode 100644 docs/Maybe.rst create mode 100644 docs/Monoid.rst create mode 100644 docs/Numbers.rst create mode 100644 docs/Strings.rst diff --git a/docs/Applicative.rst b/docs/Applicative.rst index 1474840bc..f1f42eb7e 100644 --- a/docs/Applicative.rst +++ b/docs/Applicative.rst @@ -1,7 +1,8 @@ Applicative =========== -#### Functor +Functor +~~~~~~~ ```haskell class Functor (f :: * -> *) where @@ -17,7 +18,8 @@ class Functor (f :: * -> *) where ($>) :: Functor f => f a -> b -> f b ``` -#### Applicatives +Applicatives +~~~~~~~~~~~~ ```haskell class Functor f => Applicative (f :: * -> *) where @@ -43,7 +45,8 @@ orEmpty :: Alternative f => Bool -> a -> f a eitherA :: (Alternative f) => f a -> f b -> f (Either a b) ``` -#### Alternative +Alternative +~~~~~~~~~~~ ```haskell class Applicative f => Alternative (f :: * -> *) where diff --git a/docs/Bool.rst b/docs/Bool.rst new file mode 100644 index 000000000..897a6ae65 --- /dev/null +++ b/docs/Bool.rst @@ -0,0 +1,2 @@ +Bool +===== diff --git a/docs/Either.rst b/docs/Either.rst new file mode 100644 index 000000000..4b0819784 --- /dev/null +++ b/docs/Either.rst @@ -0,0 +1,2 @@ +Either +====== diff --git a/docs/Folds.rst b/docs/Folds.rst new file mode 100644 index 000000000..3a76da4ad --- /dev/null +++ b/docs/Folds.rst @@ -0,0 +1,2 @@ +Folds +===== diff --git a/docs/List.rst b/docs/List.rst index 3135a4926..53f6275d2 100644 --- a/docs/List.rst +++ b/docs/List.rst @@ -1,7 +1,8 @@ List ==== -#### Slicing +Slicing +~~~~~~~ ```haskell head :: Foldable f => f a -> Maybe a @@ -47,7 +48,8 @@ drop :: Int -> [a] -> [a] take :: Int -> [a] -> [a] ``` -#### Unpacking +Unpacking +~~~~~~~~~ ```haskell uncons :: [a] -> Maybe (a, [a]) @@ -57,19 +59,22 @@ uncons :: [a] -> Maybe (a, [a]) unsnoc :: [x] -> Maybe ([x],x) ``` -#### Sorting +Sorting +~~~~~~~~~ ```haskell sortOn :: Ord o => (a -> o) -> [a] -> [a] ``` -#### Removing +Removing +~~~~~~~~~ ```haskell ordNub :: Ord a => [a] -> [a] ``` -#### Splitting +Splitting +~~~~~~~~~ ```haskell splitAt :: Int -> [a] -> ([a], [a]) @@ -83,13 +88,15 @@ splitAt :: Int -> [a] -> ([a], [a]) intercalate :: [a] -> [[a]] -> [a] ``` -#### Comparison +Comparison +~~~~~~~~~ ```haskell isPrefixOf :: Eq a => [a] -> [a] -> Bool ``` -#### Filter +Filtering +~~~~~~~~~ ```haskell filter :: (a -> Bool) -> [a] -> [a] diff --git a/docs/Maybe.rst b/docs/Maybe.rst new file mode 100644 index 000000000..39fcdbb68 --- /dev/null +++ b/docs/Maybe.rst @@ -0,0 +1,2 @@ +Maybe +===== diff --git a/docs/Monad.rst b/docs/Monad.rst index 53452fdc2..9441ef5df 100644 --- a/docs/Monad.rst +++ b/docs/Monad.rst @@ -1,7 +1,8 @@ Monads ====== -#### Monad +Monad +~~~~~ ```haskell class Applicative m => Monad (m :: * -> *) where @@ -119,7 +120,8 @@ ap :: Monad m => m (a -> b) -> m a -> m b (<$!>) :: Monad m => (a -> b) -> m a -> m b ``` -#### MonadPlus +MonadPlus +~~~~~~~~~ ```haskell class (Alternative m, Monad m) => MonadPlus (m :: * -> *) where diff --git a/docs/Monoid.rst b/docs/Monoid.rst new file mode 100644 index 000000000..86bbceb38 --- /dev/null +++ b/docs/Monoid.rst @@ -0,0 +1,2 @@ +Monoid +====== diff --git a/docs/Numbers.rst b/docs/Numbers.rst new file mode 100644 index 000000000..fcaa14edc --- /dev/null +++ b/docs/Numbers.rst @@ -0,0 +1,2 @@ +Numbers +======= diff --git a/docs/Strings.rst b/docs/Strings.rst new file mode 100644 index 000000000..2d218dd04 --- /dev/null +++ b/docs/Strings.rst @@ -0,0 +1,14 @@ +Strings +======= + +Text +~~~~ + +LText +~~~~ + +Bytestring +~~~~~~~~~~ + +LBytestring +~~~~~~~~~~~ diff --git a/docs/index.rst b/docs/index.rst index 127aba249..2a0ea5ad9 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -4,7 +4,7 @@ Protolude Documentation An alternative Prelude. .. toctree:: - :maxdepth: 1 + :maxdepth: 0 Printing Files Strings @@ -28,7 +28,7 @@ An alternative Prelude. ST Concurrency Storable - Systsem + System Map Set Tuple From 7cdf6f1cc83e69cc78b5a610389143d7f3e53335 Mon Sep 17 00:00:00 2001 From: Stephen Diehl Date: Thu, 8 Dec 2016 12:23:15 +0000 Subject: [PATCH 03/24] markdown source processor --- docs/{Either.rst => Either.md} | 0 docs/conf.py | 12 ++++++++++-- 2 files changed, 10 insertions(+), 2 deletions(-) rename docs/{Either.rst => Either.md} (100%) diff --git a/docs/Either.rst b/docs/Either.md similarity index 100% rename from docs/Either.rst rename to docs/Either.md diff --git a/docs/conf.py b/docs/conf.py index 2b8a07eaf..afc5b41fc 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -20,6 +20,9 @@ # import sys # sys.path.insert(0, os.path.abspath('.')) +import sphinx_rtd_theme +from recommonmark.parser import CommonMarkParser + # -- General configuration ------------------------------------------------ # If your documentation needs a minimal Sphinx version, state it here. @@ -40,7 +43,11 @@ templates_path = ['_templates'] # You can specify multiple suffix as a list of string: # # source_suffix = ['.rst', '.md'] -source_suffix = '.rst' + +source_parsers = { + '.md': CommonMarkParser, +} +source_suffix = ['.rst', '.md'] # The encoding of source files. # @@ -121,7 +128,7 @@ todo_include_todos = False # The theme to use for HTML and HTML Help pages. See the documentation for # a list of builtin themes. # -html_theme = 'alabaster' +html_theme = "sphinx_rtd_theme" # Theme options are theme-specific and customize the look and feel of a theme # further. For a list of options available for each theme, see the @@ -131,6 +138,7 @@ html_theme = 'alabaster' # Add any paths that contain custom themes here, relative to this directory. # html_theme_path = [] +html_theme_path = [sphinx_rtd_theme.get_html_theme_path()] # The name for this set of Sphinx documents. # " v documentation" by default. From e041d6de8a0ef7ba9ee50f2bb171059168d6bacc Mon Sep 17 00:00:00 2001 From: Stephen Diehl Date: Thu, 8 Dec 2016 12:23:56 +0000 Subject: [PATCH 04/24] added makefile --- docs/.gitignore | 1 + docs/Makefile | 225 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 226 insertions(+) create mode 100644 docs/.gitignore create mode 100644 docs/Makefile diff --git a/docs/.gitignore b/docs/.gitignore new file mode 100644 index 000000000..e35d8850c --- /dev/null +++ b/docs/.gitignore @@ -0,0 +1 @@ +_build diff --git a/docs/Makefile b/docs/Makefile new file mode 100644 index 000000000..e0d0d9ad3 --- /dev/null +++ b/docs/Makefile @@ -0,0 +1,225 @@ +# Makefile for Sphinx documentation +# + +# You can set these variables from the command line. +SPHINXOPTS = +SPHINXBUILD = sphinx-build +PAPER = +BUILDDIR = _build + +# Internal variables. +PAPEROPT_a4 = -D latex_paper_size=a4 +PAPEROPT_letter = -D latex_paper_size=letter +ALLSPHINXOPTS = -d $(BUILDDIR)/doctrees $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) . +# the i18n builder cannot share the environment and doctrees with the others +I18NSPHINXOPTS = $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) . + +.PHONY: help +help: + @echo "Please use \`make ' where is one of" + @echo " html to make standalone HTML files" + @echo " dirhtml to make HTML files named index.html in directories" + @echo " singlehtml to make a single large HTML file" + @echo " pickle to make pickle files" + @echo " json to make JSON files" + @echo " htmlhelp to make HTML files and a HTML help project" + @echo " qthelp to make HTML files and a qthelp project" + @echo " applehelp to make an Apple Help Book" + @echo " devhelp to make HTML files and a Devhelp project" + @echo " epub to make an epub" + @echo " epub3 to make an epub3" + @echo " latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter" + @echo " latexpdf to make LaTeX files and run them through pdflatex" + @echo " latexpdfja to make LaTeX files and run them through platex/dvipdfmx" + @echo " text to make text files" + @echo " man to make manual pages" + @echo " texinfo to make Texinfo files" + @echo " info to make Texinfo files and run them through makeinfo" + @echo " gettext to make PO message catalogs" + @echo " changes to make an overview of all changed/added/deprecated items" + @echo " xml to make Docutils-native XML files" + @echo " pseudoxml to make pseudoxml-XML files for display purposes" + @echo " linkcheck to check all external links for integrity" + @echo " doctest to run all doctests embedded in the documentation (if enabled)" + @echo " coverage to run coverage check of the documentation (if enabled)" + @echo " dummy to check syntax errors of document sources" + +.PHONY: clean +clean: + rm -rf $(BUILDDIR)/* + +.PHONY: html +html: + $(SPHINXBUILD) -b html $(ALLSPHINXOPTS) $(BUILDDIR)/html + @echo + @echo "Build finished. The HTML pages are in $(BUILDDIR)/html." + +.PHONY: dirhtml +dirhtml: + $(SPHINXBUILD) -b dirhtml $(ALLSPHINXOPTS) $(BUILDDIR)/dirhtml + @echo + @echo "Build finished. The HTML pages are in $(BUILDDIR)/dirhtml." + +.PHONY: singlehtml +singlehtml: + $(SPHINXBUILD) -b singlehtml $(ALLSPHINXOPTS) $(BUILDDIR)/singlehtml + @echo + @echo "Build finished. The HTML page is in $(BUILDDIR)/singlehtml." + +.PHONY: pickle +pickle: + $(SPHINXBUILD) -b pickle $(ALLSPHINXOPTS) $(BUILDDIR)/pickle + @echo + @echo "Build finished; now you can process the pickle files." + +.PHONY: json +json: + $(SPHINXBUILD) -b json $(ALLSPHINXOPTS) $(BUILDDIR)/json + @echo + @echo "Build finished; now you can process the JSON files." + +.PHONY: htmlhelp +htmlhelp: + $(SPHINXBUILD) -b htmlhelp $(ALLSPHINXOPTS) $(BUILDDIR)/htmlhelp + @echo + @echo "Build finished; now you can run HTML Help Workshop with the" \ + ".hhp project file in $(BUILDDIR)/htmlhelp." + +.PHONY: qthelp +qthelp: + $(SPHINXBUILD) -b qthelp $(ALLSPHINXOPTS) $(BUILDDIR)/qthelp + @echo + @echo "Build finished; now you can run "qcollectiongenerator" with the" \ + ".qhcp project file in $(BUILDDIR)/qthelp, like this:" + @echo "# qcollectiongenerator $(BUILDDIR)/qthelp/protolude.qhcp" + @echo "To view the help file:" + @echo "# assistant -collectionFile $(BUILDDIR)/qthelp/protolude.qhc" + +.PHONY: applehelp +applehelp: + $(SPHINXBUILD) -b applehelp $(ALLSPHINXOPTS) $(BUILDDIR)/applehelp + @echo + @echo "Build finished. The help book is in $(BUILDDIR)/applehelp." + @echo "N.B. You won't be able to view it unless you put it in" \ + "~/Library/Documentation/Help or install it in your application" \ + "bundle." + +.PHONY: devhelp +devhelp: + $(SPHINXBUILD) -b devhelp $(ALLSPHINXOPTS) $(BUILDDIR)/devhelp + @echo + @echo "Build finished." + @echo "To view the help file:" + @echo "# mkdir -p $$HOME/.local/share/devhelp/protolude" + @echo "# ln -s $(BUILDDIR)/devhelp $$HOME/.local/share/devhelp/protolude" + @echo "# devhelp" + +.PHONY: epub +epub: + $(SPHINXBUILD) -b epub $(ALLSPHINXOPTS) $(BUILDDIR)/epub + @echo + @echo "Build finished. The epub file is in $(BUILDDIR)/epub." + +.PHONY: epub3 +epub3: + $(SPHINXBUILD) -b epub3 $(ALLSPHINXOPTS) $(BUILDDIR)/epub3 + @echo + @echo "Build finished. The epub3 file is in $(BUILDDIR)/epub3." + +.PHONY: latex +latex: + $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex + @echo + @echo "Build finished; the LaTeX files are in $(BUILDDIR)/latex." + @echo "Run \`make' in that directory to run these through (pdf)latex" \ + "(use \`make latexpdf' here to do that automatically)." + +.PHONY: latexpdf +latexpdf: + $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex + @echo "Running LaTeX files through pdflatex..." + $(MAKE) -C $(BUILDDIR)/latex all-pdf + @echo "pdflatex finished; the PDF files are in $(BUILDDIR)/latex." + +.PHONY: latexpdfja +latexpdfja: + $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex + @echo "Running LaTeX files through platex and dvipdfmx..." + $(MAKE) -C $(BUILDDIR)/latex all-pdf-ja + @echo "pdflatex finished; the PDF files are in $(BUILDDIR)/latex." + +.PHONY: text +text: + $(SPHINXBUILD) -b text $(ALLSPHINXOPTS) $(BUILDDIR)/text + @echo + @echo "Build finished. The text files are in $(BUILDDIR)/text." + +.PHONY: man +man: + $(SPHINXBUILD) -b man $(ALLSPHINXOPTS) $(BUILDDIR)/man + @echo + @echo "Build finished. The manual pages are in $(BUILDDIR)/man." + +.PHONY: texinfo +texinfo: + $(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo + @echo + @echo "Build finished. The Texinfo files are in $(BUILDDIR)/texinfo." + @echo "Run \`make' in that directory to run these through makeinfo" \ + "(use \`make info' here to do that automatically)." + +.PHONY: info +info: + $(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo + @echo "Running Texinfo files through makeinfo..." + make -C $(BUILDDIR)/texinfo info + @echo "makeinfo finished; the Info files are in $(BUILDDIR)/texinfo." + +.PHONY: gettext +gettext: + $(SPHINXBUILD) -b gettext $(I18NSPHINXOPTS) $(BUILDDIR)/locale + @echo + @echo "Build finished. The message catalogs are in $(BUILDDIR)/locale." + +.PHONY: changes +changes: + $(SPHINXBUILD) -b changes $(ALLSPHINXOPTS) $(BUILDDIR)/changes + @echo + @echo "The overview file is in $(BUILDDIR)/changes." + +.PHONY: linkcheck +linkcheck: + $(SPHINXBUILD) -b linkcheck $(ALLSPHINXOPTS) $(BUILDDIR)/linkcheck + @echo + @echo "Link check complete; look for any errors in the above output " \ + "or in $(BUILDDIR)/linkcheck/output.txt." + +.PHONY: doctest +doctest: + $(SPHINXBUILD) -b doctest $(ALLSPHINXOPTS) $(BUILDDIR)/doctest + @echo "Testing of doctests in the sources finished, look at the " \ + "results in $(BUILDDIR)/doctest/output.txt." + +.PHONY: coverage +coverage: + $(SPHINXBUILD) -b coverage $(ALLSPHINXOPTS) $(BUILDDIR)/coverage + @echo "Testing of coverage in the sources finished, look at the " \ + "results in $(BUILDDIR)/coverage/python.txt." + +.PHONY: xml +xml: + $(SPHINXBUILD) -b xml $(ALLSPHINXOPTS) $(BUILDDIR)/xml + @echo + @echo "Build finished. The XML files are in $(BUILDDIR)/xml." + +.PHONY: pseudoxml +pseudoxml: + $(SPHINXBUILD) -b pseudoxml $(ALLSPHINXOPTS) $(BUILDDIR)/pseudoxml + @echo + @echo "Build finished. The pseudo-XML files are in $(BUILDDIR)/pseudoxml." + +.PHONY: dummy +dummy: + $(SPHINXBUILD) -b dummy $(ALLSPHINXOPTS) $(BUILDDIR)/dummy + @echo + @echo "Build finished. Dummy builder generates no files." From c28fa6b00ce87285d8150dd1f8dadd366c63a056 Mon Sep 17 00:00:00 2001 From: Stephen Diehl Date: Thu, 8 Dec 2016 13:12:42 +0000 Subject: [PATCH 05/24] debug module --- docs/{Applicative.rst => Applicative.md} | 6 ++-- docs/{Bool.rst => Bool.md} | 0 docs/Debug.md | 38 ++++++++++++++++++++++++ docs/{Exceptions.rst => Exceptions.md} | 0 docs/{Folds.rst => Folds.md} | 0 docs/{List.rst => List.md} | 14 ++++----- docs/{Maybe.rst => Maybe.md} | 0 docs/{Monad.rst => Monad.md} | 4 +-- docs/{Monoid.rst => Monoid.md} | 0 docs/{Numbers.rst => Numbers.md} | 0 docs/{Strings.rst => Strings.md} | 0 docs/{Tuple.rst => Tuple.md} | 0 docs/{TypeLevel.rst => TypeLevel.md} | 10 +++++++ docs/index.rst | 1 + 14 files changed, 61 insertions(+), 12 deletions(-) rename docs/{Applicative.rst => Applicative.md} (97%) rename docs/{Bool.rst => Bool.md} (100%) create mode 100644 docs/Debug.md rename docs/{Exceptions.rst => Exceptions.md} (100%) rename docs/{Folds.rst => Folds.md} (100%) rename docs/{List.rst => List.md} (94%) rename docs/{Maybe.rst => Maybe.md} (100%) rename docs/{Monad.rst => Monad.md} (99%) rename docs/{Monoid.rst => Monoid.md} (100%) rename docs/{Numbers.rst => Numbers.md} (100%) rename docs/{Strings.rst => Strings.md} (100%) rename docs/{Tuple.rst => Tuple.md} (100%) rename docs/{TypeLevel.rst => TypeLevel.md} (90%) diff --git a/docs/Applicative.rst b/docs/Applicative.md similarity index 97% rename from docs/Applicative.rst rename to docs/Applicative.md index f1f42eb7e..80fc3d8f1 100644 --- a/docs/Applicative.rst +++ b/docs/Applicative.md @@ -2,7 +2,7 @@ Applicative =========== Functor -~~~~~~~ +------- ```haskell class Functor (f :: * -> *) where @@ -19,7 +19,7 @@ class Functor (f :: * -> *) where ``` Applicatives -~~~~~~~~~~~~ +------- ```haskell class Functor f => Applicative (f :: * -> *) where @@ -46,7 +46,7 @@ eitherA :: (Alternative f) => f a -> f b -> f (Either a b) ``` Alternative -~~~~~~~~~~~ +------- ```haskell class Applicative f => Alternative (f :: * -> *) where diff --git a/docs/Bool.rst b/docs/Bool.md similarity index 100% rename from docs/Bool.rst rename to docs/Bool.md diff --git a/docs/Debug.md b/docs/Debug.md new file mode 100644 index 000000000..0a1030ff5 --- /dev/null +++ b/docs/Debug.md @@ -0,0 +1,38 @@ +Debug +===== + +```haskell +undefined :: a +``` + +```haskell +notImplemented :: a +``` + +```haskell +trace :: Print b => b -> a -> a +``` + +```haskell +traceM :: (Monad m) => Text -> m () +``` + +```haskell +traceId :: Text -> Text +``` + +```haskell +traceShowM :: (P.Show a, Monad m) => a -> m () +``` + +```haskell +traceShowId :: P.Show a => a -> a +``` + +```haskell +traceShow :: P.Show a => a -> b -> b +``` + +```haskell +traceIO :: Print b => b -> a -> IO a +``` diff --git a/docs/Exceptions.rst b/docs/Exceptions.md similarity index 100% rename from docs/Exceptions.rst rename to docs/Exceptions.md diff --git a/docs/Folds.rst b/docs/Folds.md similarity index 100% rename from docs/Folds.rst rename to docs/Folds.md diff --git a/docs/List.rst b/docs/List.md similarity index 94% rename from docs/List.rst rename to docs/List.md index 53f6275d2..97e40763e 100644 --- a/docs/List.rst +++ b/docs/List.md @@ -2,7 +2,7 @@ List ==== Slicing -~~~~~~~ +------- ```haskell head :: Foldable f => f a -> Maybe a @@ -49,7 +49,7 @@ take :: Int -> [a] -> [a] ``` Unpacking -~~~~~~~~~ +--------- ```haskell uncons :: [a] -> Maybe (a, [a]) @@ -60,21 +60,21 @@ unsnoc :: [x] -> Maybe ([x],x) ``` Sorting -~~~~~~~~~ +--------- ```haskell sortOn :: Ord o => (a -> o) -> [a] -> [a] ``` Removing -~~~~~~~~~ +--------- ```haskell ordNub :: Ord a => [a] -> [a] ``` Splitting -~~~~~~~~~ +--------- ```haskell splitAt :: Int -> [a] -> ([a], [a]) @@ -89,14 +89,14 @@ intercalate :: [a] -> [[a]] -> [a] ``` Comparison -~~~~~~~~~ +--------- ```haskell isPrefixOf :: Eq a => [a] -> [a] -> Bool ``` Filtering -~~~~~~~~~ +--------- ```haskell filter :: (a -> Bool) -> [a] -> [a] diff --git a/docs/Maybe.rst b/docs/Maybe.md similarity index 100% rename from docs/Maybe.rst rename to docs/Maybe.md diff --git a/docs/Monad.rst b/docs/Monad.md similarity index 99% rename from docs/Monad.rst rename to docs/Monad.md index 9441ef5df..4b7282f8e 100644 --- a/docs/Monad.rst +++ b/docs/Monad.md @@ -2,7 +2,7 @@ Monads ====== Monad -~~~~~ +----- ```haskell class Applicative m => Monad (m :: * -> *) where @@ -121,7 +121,7 @@ ap :: Monad m => m (a -> b) -> m a -> m b ``` MonadPlus -~~~~~~~~~ +----- ```haskell class (Alternative m, Monad m) => MonadPlus (m :: * -> *) where diff --git a/docs/Monoid.rst b/docs/Monoid.md similarity index 100% rename from docs/Monoid.rst rename to docs/Monoid.md diff --git a/docs/Numbers.rst b/docs/Numbers.md similarity index 100% rename from docs/Numbers.rst rename to docs/Numbers.md diff --git a/docs/Strings.rst b/docs/Strings.md similarity index 100% rename from docs/Strings.rst rename to docs/Strings.md diff --git a/docs/Tuple.rst b/docs/Tuple.md similarity index 100% rename from docs/Tuple.rst rename to docs/Tuple.md diff --git a/docs/TypeLevel.rst b/docs/TypeLevel.md similarity index 90% rename from docs/TypeLevel.rst rename to docs/TypeLevel.md index 3a0346a3d..7da15d2fc 100644 --- a/docs/TypeLevel.rst +++ b/docs/TypeLevel.md @@ -30,6 +30,16 @@ vacuous :: Functor f => f Void -> f a data Proxy (t :: k) = Proxy ``` +#### Symbol + +* symbolVal +* someSymbolVal + +#### Nat + +* natVal +* someNatVal + #### Type Equality ```haskell diff --git a/docs/index.rst b/docs/index.rst index 2a0ea5ad9..87fc5185f 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -6,6 +6,7 @@ An alternative Prelude. .. toctree:: :maxdepth: 0 Printing + Debug Files Strings Function From b32c80d0bbb6ebd391f075b1027472e7bb21733a Mon Sep 17 00:00:00 2001 From: Stephen Diehl Date: Sat, 10 Dec 2016 12:46:48 +0000 Subject: [PATCH 06/24] basic hierarchy in place --- docs/Applicative.md | 4 -- docs/Debug.md | 58 +++++++++++++++++++++++++++ docs/Exceptions.md | 2 +- docs/Function.md | 98 +++++++++++++++++++++++++++++++++++++++++++++ docs/Function.rst | 83 -------------------------------------- docs/Monad.md | 1 - docs/Strings.md | 52 ++++++++++++++++++++++-- docs/Tuple.md | 86 ++++++++++++++++++--------------------- docs/index.rst | 8 ++-- src/Protolude.hs | 13 +++++- stack.yaml | 2 +- 11 files changed, 261 insertions(+), 146 deletions(-) create mode 100644 docs/Function.md delete mode 100644 docs/Function.rst diff --git a/docs/Applicative.md b/docs/Applicative.md index 80fc3d8f1..ef14d9b28 100644 --- a/docs/Applicative.md +++ b/docs/Applicative.md @@ -29,10 +29,6 @@ class Functor f => Applicative (f :: * -> *) where (<*) :: f a -> f b -> f a ``` -```haskell -(<$>) :: Functor f => (a -> b) -> f a -> f b -``` - ```haskell orAlt :: (Alternative f, Monoid a) => f a -> f a ``` diff --git a/docs/Debug.md b/docs/Debug.md index 0a1030ff5..37363798c 100644 --- a/docs/Debug.md +++ b/docs/Debug.md @@ -1,38 +1,96 @@ Debug ===== +Stubbing +-------- + +#### undefined + ```haskell undefined :: a ``` +An undefined expression standing in for an incomplete program, unevaluated type +witness, or unreachable code branch. + +*Example*: + +```haskell +> import Foreign.Storable +> print (sizeOf (undefined :: Int)) +8 +``` + +#### notImplemented + ```haskell notImplemented :: a ``` +An undefined expression standing in for a yet to completed program. + +*Example*: + +```haskell +main :: IO () +main = notImplemented +``` + +Tracing +------- + +#### trace + ```haskell trace :: Print b => b -> a -> a ``` +*Example*: + +#### traceM + ```haskell traceM :: (Monad m) => Text -> m () ``` +*Example*: + +#### traceId + ```haskell traceId :: Text -> Text ``` +*Example*: + +#### traceShowM + ```haskell traceShowM :: (P.Show a, Monad m) => a -> m () ``` +*Example*: + +#### traceShowId + ```haskell traceShowId :: P.Show a => a -> a ``` +*Example*: + +#### traceShow + ```haskell traceShow :: P.Show a => a -> b -> b ``` +*Example*: + +#### traceIO + ```haskell traceIO :: Print b => b -> a -> IO a ``` + +*Example*: diff --git a/docs/Exceptions.md b/docs/Exceptions.md index 6a33cef03..4817c97bd 100644 --- a/docs/Exceptions.md +++ b/docs/Exceptions.md @@ -61,7 +61,7 @@ throwSTM :: Exception e => e -> STM a throwError :: MonadError e m => e -> m a ``` -#### Panic +#### Fatal Errors ```haskell data FatalError = FatalError {msg :: Text} diff --git a/docs/Function.md b/docs/Function.md new file mode 100644 index 000000000..c28a7b4e2 --- /dev/null +++ b/docs/Function.md @@ -0,0 +1,98 @@ +Functions +========= + +Composition +----------- + +#### $ + +```haskell +($) :: (a -> b) -> a -> b +``` + +*Example*: + +#### . + +```haskell +(.) :: (b -> c) -> (a -> b) -> a -> c +``` + +*Example*: + +#### & + +```haskell +(&) :: a -> (a -> b) -> b +``` + +*Example*: + +#### flip + +```haskell +flip :: (a -> b -> c) -> b -> a -> c +``` + +*Example*: + +#### on + +```haskell +on :: (b -> b -> c) -> (a -> b) -> a -> a -> c +``` + +*Example*: + +#### const + +```haskell +const :: a -> b -> a +``` + +*Example*: + +#### fix + +```haskell +fix :: (a -> a) -> a +``` + +*Example*: + +#### identity + +```haskell +identity :: a -> a +``` + +The identity function maps any value to itself. + +*Example*: + +Strictness +----------- + +#### $! + +```haskell +($!) :: NFData a => (a -> b) -> a -> b +``` + +*Example*: + +#### $!! + +```haskell +($!!) :: NFData a => (a -> b) -> a -> b +``` + +*Example*: + +#### force + +```haskell +force :: NFData a => a -> a +``` + +*Example*: diff --git a/docs/Function.rst b/docs/Function.rst deleted file mode 100644 index 2f5f1ed70..000000000 --- a/docs/Function.rst +++ /dev/null @@ -1,83 +0,0 @@ -Functions -========= - -.. highlight:: haskell - -$ -*** - -:: - - ($) :: (a -> b) -> a -> b - -& -*** - -:: - - (&) :: a -> (a -> b) -> b - -. -*** - -:: - - (.) :: (b -> c) -> (a -> b) -> a -> c - - -flip -**** - -:: - - flip :: (a -> b -> c) -> b -> a -> c - - -on -*** - -:: - - on :: (b -> b -> c) -> (a -> b) -> a -> a -> c - -const -***** - -:: - - const :: a -> b -> a - -fix -*** - -:: - - fix :: (a -> a) -> a - -identity -******** - -:: - - identity :: a -> a - -$! -*** - -:: - - ($!) :: NFData a => (a -> b) -> a -> b - -$!! -*** - -:: - - ($!!) :: NFData a => (a -> b) -> a -> b - -force -***** - -:: - - force :: NFData a => a -> a diff --git a/docs/Monad.md b/docs/Monad.md index 4b7282f8e..9e0e3e6ee 100644 --- a/docs/Monad.md +++ b/docs/Monad.md @@ -9,7 +9,6 @@ class Applicative m => Monad (m :: * -> *) where (>>=) :: m a -> (a -> m b) -> m b (>>) :: m a -> m b -> m b return :: a -> m a - GHC.Base.fail :: GHC.Base.String -> m a ``` ```haskell diff --git a/docs/Strings.md b/docs/Strings.md index 2d218dd04..57ffd8776 100644 --- a/docs/Strings.md +++ b/docs/Strings.md @@ -1,14 +1,58 @@ Strings ======= +```haskell +import qualified Data.Text as T +import qualified Data.Text.Lazy as L +``` + Text -~~~~ +---- + +The Text type represents Unicode character strings, in a time and space-efficient manner. This package provides text processing capabilities that are optimized for performance critical use, both in terms of large data quantities and high speed. LText -~~~~ +----- Bytestring -~~~~~~~~~~ +---------- LBytestring -~~~~~~~~~~~ +----------- + +Conversion +---------- + +```haskell +class StringConv a b where + strConv :: Leniency -> a -> b + +data Leniency = Lenient | Strict +``` + +```haskell +toS :: StringConv a b => a -> b +``` + +```haskell +toSL :: StringConv a b => a -> b +``` + +*Example*: + +```haskell +a :: LByteString +a = "Einstein" + +b :: Text +b = "Feynmann" + +c :: ByteString +c = "Schrödinger" + +example1 :: ByteString +example1 = toS b + +example2 :: Bool +example2 = (a == toS b) && (toS b == c) +``` diff --git a/docs/Tuple.md b/docs/Tuple.md index 5ce5679d2..f9cbb5b73 100644 --- a/docs/Tuple.md +++ b/docs/Tuple.md @@ -1,84 +1,76 @@ Tuples ====== -.. highlight:: haskell +#### fst -fst -*** - -:: - - fst :: (a, b) -> a +```haskell +fst :: (a, b) -> a +``` Extract the first component of a pair. *Example*: -:: - - > fst (1,2) - 1 +```haskell +> fst (1,2) +``` -snd -*** +#### snd -:: - - snd :: (a, b) -> b +```haskell +snd :: (a, b) -> b +``` Extract the second component of a pair. *Example*: -:: - - > snd (1,2) - 2 +```haskell +> snd (1,2) +2 +``` -swap -**** +#### swap -:: - - swap :: (a, b) -> (b, a) +```haskell +swap :: (a, b) -> (b, a) +``` Swap the components of a pair. *Example*: -:: - - > swap (1,2) - (2,1) +```haskell +> swap (1,2) +(2,1) +``` -curry -***** +#### curry -:: - - curry :: ((a, b) -> c) -> a -> b -> c +```haskell +curry :: ((a, b) -> c) -> a -> b -> c +``` curry converts an uncurried function to a curried function. *Example*: -:: +```haskell +> curry fst 1 2 +1 +``` - > curry fst 1 2 - 1 +#### uncurry -uncurry -******* - -:: - - uncurry :: (a -> b -> c) -> (a, b) -> c +```haskell +uncurry :: (a -> b -> c) -> (a, b) -> c +``` uncurry converts a curried function to a function on pairs. *Example*: -:: - - > uncurry (+) (1,2) - 3 +```haskell +> uncurry (+) (1,2) +3 +``` diff --git a/docs/index.rst b/docs/index.rst index 87fc5185f..48f8161c2 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -5,17 +5,17 @@ An alternative Prelude. .. toctree:: :maxdepth: 0 + Function + Strings + Bool + Numbers Printing Debug Files - Strings - Function Applicative Monad Maybe Either - Bool - Numbers Monoid Semigroup Bifunctor diff --git a/src/Protolude.hs b/src/Protolude.hs index 73ed2bd29..90c89de48 100644 --- a/src/Protolude.hs +++ b/src/Protolude.hs @@ -196,6 +196,7 @@ import Data.Typeable as X ( import Data.Type.Coercion as X ( Coercion(..) , coerceWith + , repr ) import Data.Type.Equality as X ( @@ -269,7 +270,17 @@ import Data.Bits as X hiding ( unsafeShiftL , unsafeShiftR ) -import Data.Word as X +import Data.Word as X ( + byteSwap16 + , byteSwap32 + , byteSwap64 + , Word + , Word16 + , Word32 + , Word64 + , Word8 + ) + import Data.Either as X import Data.Complex as X import Data.Char as X (chr) diff --git a/stack.yaml b/stack.yaml index 38583d04e..bb517b9f0 100644 --- a/stack.yaml +++ b/stack.yaml @@ -1,4 +1,4 @@ -resolver: lts-5.10 +resolver: lts-6.2 packages: - '.' extra-deps: From 8995aa71f3f846e82ad8f05690ee679e0259eee6 Mon Sep 17 00:00:00 2001 From: Stephen Diehl Date: Sat, 10 Dec 2016 13:28:32 +0000 Subject: [PATCH 07/24] bits and files --- docs/Bits.md | 147 ++++++++++++++++++++++++++++++++++++++++++++++ docs/Files.md | 28 +++++++++ docs/Numbers.md | 11 ++++ docs/Strings.md | 8 +++ docs/TypeLevel.md | 36 ++++++++++-- docs/index.rst | 3 +- 6 files changed, 228 insertions(+), 5 deletions(-) create mode 100644 docs/Bits.md create mode 100644 docs/Files.md diff --git a/docs/Bits.md b/docs/Bits.md new file mode 100644 index 000000000..c9c32e97e --- /dev/null +++ b/docs/Bits.md @@ -0,0 +1,147 @@ +Bits +==== + +Bit Operations +-------------- + +#### .&. + +```haskell +(.&.) :: Bits a => a -> a -> a +``` + +*Example*: + +#### .|. + +```haskell +(.|.) :: Bits a => a -> a -> a +``` + +*Example*: + +#### xor + +```haskell +xor :: Bits a => a -> a -> a +``` + +*Example*: + +#### complement + +```haskell +complement :: Bits a => a -> a +``` + +*Example*: + +#### shift + +*Example*: + +```haskell +shift :: Bits a => a -> Int -> a +``` + +*Example*: + +#### rotate + +```haskell +rotate :: Bits a => a -> Int -> a +``` + +*Example*: + +#### zeroBits + +```haskell +zeroBits :: Bits a => a +``` + +*Example*: + +#### bit + +```haskell +bit :: Bits a => Int -> a +``` + +*Example*: + +Bit Testing +------------ + +```haskell +setBit :: Bits a => a -> Int -> a +``` + +```haskell +clearBit :: Bits a => a -> Int -> a +``` + +```haskell +complementBit :: Bits a => a -> Int -> a +``` + +```haskell +testBit :: Bits a => a -> Int -> Bool +``` + + +```haskell +isSigned :: Bits a => a -> Bool +``` + +Bit Size +------------ + +```haskell +bitSize :: Bits a => a -> Int +``` + +```haskell +popCount :: Bits a => a -> Int +``` + +Bit Shifting +------------ + +```haskell +shiftL :: Bits a => a -> Int -> a +``` + +```haskell +shiftR :: Bits a => a -> Int -> a +``` + +Bit Rotation +------------ + +```haskell +rotate :: Bits a => a -> Int -> a +``` + +```haskell +rotateL :: Bits a => a -> Int -> a +``` + +```haskell +rotateR :: Bits a => a -> Int -> a +``` + +Byte Swapping +------------ + +```haskell +byteSwap16 :: Word16 -> Word16 +``` + +```haskell +byteSwap32 :: Word32 -> Word32 +``` + +```haskell +byteSwap64 :: Word64 -> Word64 +``` diff --git a/docs/Files.md b/docs/Files.md new file mode 100644 index 000000000..6b887e606 --- /dev/null +++ b/docs/Files.md @@ -0,0 +1,28 @@ +Files +===== + +Basic IO +-------- + +* readFile +* writeFile +* appendFile +* openFile +* withFile + +Console +------- + +* getLine +* getContents +* interact + +File Handles +------------ + +* stdin +* stdout +* stderr +* Handle +* FilePath +* IOMode(..) diff --git a/docs/Numbers.md b/docs/Numbers.md index fcaa14edc..d5de5acb0 100644 --- a/docs/Numbers.md +++ b/docs/Numbers.md @@ -1,2 +1,13 @@ Numbers ======= + +* Int8 +* Int16 +* Int32 +* Int64 +* Integer +* Word +* Word8 +* Word16 +* Word32 +* Word64 diff --git a/docs/Strings.md b/docs/Strings.md index 57ffd8776..699838302 100644 --- a/docs/Strings.md +++ b/docs/Strings.md @@ -20,6 +20,14 @@ Bytestring LBytestring ----------- +Encoding +---------- + +* encodeUtf8 +* decodeUtf8 +* decodeUtf8' +* decodeUtf8With + Conversion ---------- diff --git a/docs/TypeLevel.md b/docs/TypeLevel.md index 7da15d2fc..2ac046872 100644 --- a/docs/TypeLevel.md +++ b/docs/TypeLevel.md @@ -32,13 +32,41 @@ data Proxy (t :: k) = Proxy #### Symbol -* symbolVal -* someSymbolVal +```haskell +symbolVal :: KnownSymbol n => proxy n -> String +``` + +*Example*: + +```haskell +b :: String +b = symbolVal (Proxy :: Proxy "foo") +``` + +```haskell +someSymbolVal :: String -> SomeSymbol +``` + +*Example*: #### Nat -* natVal -* someNatVal +```haskell +natVal :: KnownNat n => proxy n -> Integer +``` + +*Example*: + +```haskell +a :: Integer +a = natVal (Proxy :: Proxy 1) +``` + +```haskell +someNatVal :: Integer -> Maybe SomeNat +``` + +*Example*: #### Type Equality diff --git a/docs/index.rst b/docs/index.rst index 48f8161c2..74f7088dc 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -10,8 +10,9 @@ An alternative Prelude. Bool Numbers Printing - Debug Files + Debug + Bits Applicative Monad Maybe From 00c2fce11afb4ed549daf67f391f1911e991935b Mon Sep 17 00:00:00 2001 From: Stephen Diehl Date: Sat, 10 Dec 2016 14:51:33 +0000 Subject: [PATCH 08/24] console functions --- docs/Files.md | 74 +++++++++++++++++----- docs/Folds.md | 160 +++++++++++++++++++++++++++++++++++++++++++++++ docs/Generics.md | 2 + docs/Hashing.md | 14 +++++ docs/Numbers.md | 18 ++++++ docs/index.rst | 1 + 6 files changed, 255 insertions(+), 14 deletions(-) create mode 100644 docs/Generics.md create mode 100644 docs/Hashing.md diff --git a/docs/Files.md b/docs/Files.md index 6b887e606..eb39fa488 100644 --- a/docs/Files.md +++ b/docs/Files.md @@ -4,25 +4,71 @@ Files Basic IO -------- -* readFile -* writeFile -* appendFile -* openFile -* withFile +#### readFile + +```haskell +readFile :: FilePath -> IO Text +``` + +#### writeFile + +```haskell +writeFile :: FilePath -> Text -> IO () +``` + +#### appendFile + +```haskell +appendFile :: FilePath -> Text -> IO () +``` Console ------- -* getLine -* getContents -* interact +#### getLine + +```haskell +getLine :: IO Text +``` + +#### getContents + +```haskell +getContents :: IO Text +``` + +#### interact + +```haskell +interact :: (Text -> Text) -> IO () +``` File Handles ------------ -* stdin -* stdout -* stderr -* Handle -* FilePath -* IOMode(..) +```haskell +data IOMode + = ReadMode + | WriteMode + | AppendMode + | ReadWriteMode +``` + +#### openFile + +```haskell +openFile :: FilePath -> IOMode -> IO Handle +``` + +#### withFile + +```haskell +withFile :: FilePath -> IOMode -> (Handle -> IO r) -> IO r +``` + + +#### stdin +#### stdout +#### stderr +#### Handle +#### FilePath diff --git a/docs/Folds.md b/docs/Folds.md index 3a76da4ad..0e3147218 100644 --- a/docs/Folds.md +++ b/docs/Folds.md @@ -1,2 +1,162 @@ Folds ===== + +Basic Folds +----------- + +```haskell +foldMap :: (Foldable t, Monoid m) => (a -> m) -> t a -> m +``` + +```haskell +foldr :: Foldable t => (a -> b -> b) -> b -> t a -> b +``` + +```haskell +foldl :: Foldable t => (b -> a -> b) -> b -> t a -> b +``` + +```haskell +foldr' :: Foldable t => (a -> b -> b) -> b -> t a -> b +``` + +```haskell +foldl' :: Foldable t => (b -> a -> b) -> b -> t a -> b +``` + +```haskell +fold :: Foldable t => Monoid m => t m -> m +``` + +```haskell +toList :: Foldable t => t a -> [a] +``` + +```haskell +null :: Foldable t => t a -> Bool +``` + +```haskell +length :: Foldable t => t a -> Int +``` + +```haskell +elem :: (Eq a, Foldable t) => a -> t a -> Bool +``` + +```haskell +maximum :: (Ord a, Foldable t) => t a -> a +``` + +```haskell +minimum :: (Ord a, Foldable t) => t a -> a +``` + +```haskell +sum :: (Num a, Foldable f) => f a -> a +``` + +```haskell +product :: (Num a, Foldable f) => f a -> a +``` + +#### Folding actions + +```haskell +traverse_ :: (Foldable t, Applicative f) => (a -> f b) -> t a -> f () +``` + +```haskell +for_ :: (Foldable t, Applicative f) => t a -> (a -> f b) -> f () +``` + +*Example*: + +```haskell +>>> for_ [1..4] print +1 +2 +3 +4 +``` + + +#### Applicative Folds + +```haskell +sequenceA_ :: (Foldable t, Applicative f) => t (f a) -> f () +``` + +```haskell +asum :: (Foldable t, Alternative f) => t (f a) -> f a +``` + +#### Monadic Folds + +```haskell +mapM_ :: (Foldable t, Monad m) => (a -> m b) -> t a -> m () +``` + +```haskell +forM_ :: (Foldable t, Monad m) => t a -> (a -> m b) -> m () +``` + +```haskell +sequence_ :: (Foldable t, Monad m) => t (m a) -> m () +``` + +```haskell +msum :: (Foldable t, MonadPlus m) => t (m a) -> m a +``` + +```haskell +foldrM :: (Foldable t, Monad m) => (a -> b -> m b) -> b -> t a -> m b +``` + +```haskell +foldlM :: (Foldable t, Monad m) => (b -> a -> m b) -> b -> t a -> m b +``` + +#### Specialized folds + +```haskell +concat :: Foldable t => t [a] -> [a] +``` + +```haskell +concatMap :: Foldable t => (a -> [b]) -> t a -> [b] +``` + +```haskell +and :: Foldable t => t Bool -> Bool +``` + +```haskell +or :: Foldable t => t Bool -> Bool +``` + +```haskell +any :: Foldable t => (a -> Bool) -> t a -> Bool +``` + +```haskell +all :: Foldable t => (a -> Bool) -> t a -> Bool +``` + +```haskell +maximumBy :: Foldable t => (a -> a -> Ordering) -> t a -> a +``` + +```haskell +minimumBy :: Foldable t => (a -> a -> Ordering) -> t a -> a +``` + +#### Searches + +```haskell +notElem :: (Foldable t, Eq a) => a -> t a -> Bool +``` + +```haskell +find :: Foldable t => (a -> Bool) -> t a -> Maybe a +``` diff --git a/docs/Generics.md b/docs/Generics.md new file mode 100644 index 000000000..ab46d3cda --- /dev/null +++ b/docs/Generics.md @@ -0,0 +1,2 @@ +Generics +======== diff --git a/docs/Hashing.md b/docs/Hashing.md new file mode 100644 index 000000000..db193d977 --- /dev/null +++ b/docs/Hashing.md @@ -0,0 +1,14 @@ +Hashing +======= + +```haskell +hashWithSalt :: Hashable a => Int -> a -> Int +``` + +```haskell +hash :: Hashable a => a -> Int +``` + +```haskell +hashUsing :: Hashable b => (a -> b) -> Int -> a -> Int +``` diff --git a/docs/Numbers.md b/docs/Numbers.md index d5de5acb0..134ae728f 100644 --- a/docs/Numbers.md +++ b/docs/Numbers.md @@ -11,3 +11,21 @@ Numbers * Word16 * Word32 * Word64 + +Arithemtic +---------- + +Trigonometric +------------- + +Comparisons +----------- + +Ratios +------ + +Complex Numbers +--------------- + +Conversions +----------- diff --git a/docs/index.rst b/docs/index.rst index 74f7088dc..98aedfc9d 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -35,6 +35,7 @@ An alternative Prelude. Set Tuple Generics + Hashable TypeLevel Unsafe From 6cb17bb94b8bc31bd0a32e3c2d0a4453bc914eab Mon Sep 17 00:00:00 2001 From: Stephen Diehl Date: Sat, 10 Dec 2016 16:01:47 +0000 Subject: [PATCH 09/24] utility functions --- docs/Applicative.md | 13 +++++++++++ docs/Bits.md | 55 +++++++++++++++++++++++++++++++++++++++++++++ docs/Bool.md | 4 ++++ docs/Exceptions.md | 18 +++++++++++++-- docs/Function.md | 16 +++++++++++++ docs/List.md | 4 ++++ docs/Monad.md | 16 +++++++++++++ docs/Monoid.md | 35 +++++++++++++++++++++++++++++ 8 files changed, 159 insertions(+), 2 deletions(-) diff --git a/docs/Applicative.md b/docs/Applicative.md index ef14d9b28..d21dd9b99 100644 --- a/docs/Applicative.md +++ b/docs/Applicative.md @@ -41,6 +41,11 @@ orEmpty :: Alternative f => Bool -> a -> f a eitherA :: (Alternative f) => f a -> f b -> f (Either a b) ``` +```haskell +pass :: Applicative f => f () +``` + + Alternative ------- @@ -75,3 +80,11 @@ liftA :: Applicative f => (a -> b) -> f a -> f b ```haskell empty :: Alternative f => f a ``` + +```haskell +guarded :: (Alternative f) => (a -> Bool) -> a -> f a +``` + +```haskell +guardedA :: (Functor f, Alternative t) => (a -> f Bool) -> a -> f (t a) +``` diff --git a/docs/Bits.md b/docs/Bits.md index c9c32e97e..9fd8afc4e 100644 --- a/docs/Bits.md +++ b/docs/Bits.md @@ -1,6 +1,14 @@ Bits ==== +```haskell +{-# LANGUAGE BinaryLiterals #-} +``` + +```python +42 = 0b101010 +``` + Bit Operations -------------- @@ -28,12 +36,31 @@ xor :: Bits a => a -> a -> a *Example*: +```haskell +> True `xor` False +True + +> True `xor` True +False + +> 0b101 `xor` 0b011 +6 -- 0b110 +``` + #### complement ```haskell complement :: Bits a => a -> a ``` +```haskell +> complement True +False + +> complement 0b101 +-2 -- -0b010 +``` + *Example*: #### shift @@ -81,19 +108,47 @@ setBit :: Bits a => a -> Int -> a clearBit :: Bits a => a -> Int -> a ``` +#### complementBit + ```haskell complementBit :: Bits a => a -> Int -> a ``` +*Example*: + +```haskell +λ> 0b100 `complementBit` 1 +6 -- 0b110 +``` + +#### testBit + ```haskell testBit :: Bits a => a -> Int -> Bool ``` +*Example*: + +```haskell +> 0b10 `testBit` 0 +False +> 0b10 `testBit` 1 +True +``` + +#### isSigned ```haskell isSigned :: Bits a => a -> Bool ``` +```haskell +> isSigned 42 +True +> isSigned True +False +``` + Bit Size ------------ diff --git a/docs/Bool.md b/docs/Bool.md index 897a6ae65..d1ea2ca21 100644 --- a/docs/Bool.md +++ b/docs/Bool.md @@ -1,2 +1,6 @@ Bool ===== + +```haskell +bool :: a -> a -> Bool -> a +``` diff --git a/docs/Exceptions.md b/docs/Exceptions.md index 4817c97bd..88bd82f89 100644 --- a/docs/Exceptions.md +++ b/docs/Exceptions.md @@ -1,5 +1,5 @@ -Exception Handling -================== +Exceptions +========== #### MonadError @@ -61,6 +61,20 @@ throwSTM :: Exception e => e -> STM a throwError :: MonadError e m => e -> m a ``` +#### Utilities + +```haskell +hush :: Alternative m => Either e a -> m a +``` + +```haskell +note :: (MonadError e m, Applicative m) => e -> Maybe a -> m a +``` + +```haskell +tryIO :: MonadIO m => IO a -> ExceptT IOException m a +``` + #### Fatal Errors ```haskell diff --git a/docs/Function.md b/docs/Function.md index c28a7b4e2..120377cc6 100644 --- a/docs/Function.md +++ b/docs/Function.md @@ -68,8 +68,24 @@ identity :: a -> a The identity function maps any value to itself. +#### applyN + +Apply a function to a value `n` times. + *Example*: +```haskell +applyN :: Int -> (a -> a) -> a -> a +``` + +```haskell +> applyN 25 (+2) 0 +50 + +> applyN 3 (1:) [] +[1,1,1] +``` + Strictness ----------- diff --git a/docs/List.md b/docs/List.md index 97e40763e..7c3b64ba6 100644 --- a/docs/List.md +++ b/docs/List.md @@ -59,6 +59,10 @@ uncons :: [a] -> Maybe (a, [a]) unsnoc :: [x] -> Maybe ([x],x) ``` +```haskell +list :: [b] -> (a -> b) -> [a] -> [b] +``` + Sorting --------- diff --git a/docs/Monad.md b/docs/Monad.md index 9e0e3e6ee..78d0ea4fa 100644 --- a/docs/Monad.md +++ b/docs/Monad.md @@ -119,6 +119,22 @@ ap :: Monad m => m (a -> b) -> m a -> m b (<$!>) :: Monad m => (a -> b) -> m a -> m b ``` +```haskell +whenM :: Monad m => m Bool -> m () -> m () +``` + +```haskell +unlessM :: Monad m => m Bool -> m () -> m () +``` + +```haskell +ifM :: Monad m => m Bool -> m a -> m a -> m a +``` + +```haskell +guardM :: MonadPlus m => m Bool -> m () +``` + MonadPlus ----- diff --git a/docs/Monoid.md b/docs/Monoid.md index 86bbceb38..fbe4c7956 100644 --- a/docs/Monoid.md +++ b/docs/Monoid.md @@ -1,2 +1,37 @@ Monoid ====== + +Monoid +------ + +Semigroup +--------- + + +```haskell +option :: b -> (a -> b) -> Option a -> b +``` + +```haskell +diff :: Semigroup m => m -> Endo m +``` + +```haskell +cycle1 :: Semigroup m => m -> m +``` + +```haskell +stimesMonoid :: (Integral b, Monoid a) => b -> a -> a +``` + +```haskell +stimesIdempotent :: Integral b => b -> a -> a +``` + +```haskell +stimesIdempotentMonoid :: (Integral b, Monoid a) => b -> a -> a +``` + +```haskell +mtimesDefault :: (Integral b, Monoid a) => b -> a -> a +``` From a33669ca6dabf827785a50019524624388f1f42b Mon Sep 17 00:00:00 2001 From: Stephen Diehl Date: Mon, 12 Dec 2016 11:03:34 +0000 Subject: [PATCH 10/24] maybe functions --- docs/Bifunctor.md | 2 ++ docs/Maybe.md | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+) create mode 100644 docs/Bifunctor.md diff --git a/docs/Bifunctor.md b/docs/Bifunctor.md new file mode 100644 index 000000000..a3878ece5 --- /dev/null +++ b/docs/Bifunctor.md @@ -0,0 +1,2 @@ +Bifunctor +========= diff --git a/docs/Maybe.md b/docs/Maybe.md index 39fcdbb68..e155d4122 100644 --- a/docs/Maybe.md +++ b/docs/Maybe.md @@ -1,2 +1,38 @@ Maybe ===== + +```haskell +maybe :: b -> (a -> b) -> Maybe a -> b +``` + +```haskell +isJust :: Maybe a -> Bool +``` + +```haskell +isNothing :: Maybe a -> Bool +``` + +```haskell +fromJust :: Maybe a -> a +``` + +```haskell +fromMaybe :: a -> Maybe a -> a +``` + +```haskell +listToMaybe :: [a] -> Maybe a +``` + +```haskell +maybeToList :: Maybe a -> [a] +``` + +```haskell +catMaybes :: [Maybe a] -> [a] +``` + +```haskell +mapMaybe :: (a -> Maybe b) -> [a] -> [b] +``` From c692eb03fbae6f4a74a76ed4fd3e4fef68671233 Mon Sep 17 00:00:00 2001 From: Stephen Diehl Date: Mon, 12 Dec 2016 11:04:52 +0000 Subject: [PATCH 11/24] only export byteswap functions for ghc >7.6 --- src/Protolude.hs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/Protolude.hs b/src/Protolude.hs index 90c89de48..385099bcb 100644 --- a/src/Protolude.hs +++ b/src/Protolude.hs @@ -271,14 +271,16 @@ import Data.Bits as X hiding ( , unsafeShiftR ) import Data.Word as X ( - byteSwap16 - , byteSwap32 - , byteSwap64 - , Word + Word , Word16 , Word32 , Word64 , Word8 +#if (__GLASGOW_HASKELL__ >= 710) + , byteSwap16 + , byteSwap32 + , byteSwap64 +#endif ) import Data.Either as X From 66958def935e728e454f5773cb3c732aa763afdf Mon Sep 17 00:00:00 2001 From: Stephen Diehl Date: Mon, 12 Dec 2016 11:14:42 +0000 Subject: [PATCH 12/24] export encoding error handlers --- docs/Strings.md | 27 +++++++++++++++++++++++---- src/Protolude.hs | 9 +++++++++ 2 files changed, 32 insertions(+), 4 deletions(-) diff --git a/docs/Strings.md b/docs/Strings.md index 699838302..2f77d78b1 100644 --- a/docs/Strings.md +++ b/docs/Strings.md @@ -23,10 +23,29 @@ LBytestring Encoding ---------- -* encodeUtf8 -* decodeUtf8 -* decodeUtf8' -* decodeUtf8With +#### encodeUtf8 + +```haskell +encodeUtf8 :: Text -> ByteString +``` + +#### decodeUtf8 + +```haskell +decodeUtf8 :: ByteString -> Text +``` + +#### decodeUtf8' + +```haskell +decodeUtf8' :: ByteString -> Text +``` + +#### decodeUtf8With + +```haskell +decodeUtf8With :: Data.Text.Encoding.Error.OnDecodeError -> ByteString -> Text +``` Conversion ---------- diff --git a/src/Protolude.hs b/src/Protolude.hs index 385099bcb..c9d020d5c 100644 --- a/src/Protolude.hs +++ b/src/Protolude.hs @@ -349,6 +349,15 @@ import Data.Text.Encoding as X ( , decodeUtf8With ) +import Data.Text.Encoding.Error as X ( + OnDecodeError + , OnError + , lenientDecode + , strictDecode + , ignore + , replace + ) + -- IO import System.Exit as X import System.Environment as X (getArgs) From 257a38f68fbba6a6b16d357a61aeb4ff5fa1b0ca Mon Sep 17 00:00:00 2001 From: Stephen Diehl Date: Mon, 12 Dec 2016 13:09:18 +0000 Subject: [PATCH 13/24] functor module --- docs/Functor.md | 26 ++++++++++++++++++++++++++ docs/List.md | 4 ---- docs/Strings.md | 14 ++++++++++++-- docs/index.rst | 1 + src/Protolude.hs | 1 + 5 files changed, 40 insertions(+), 6 deletions(-) create mode 100644 docs/Functor.md diff --git a/docs/Functor.md b/docs/Functor.md new file mode 100644 index 000000000..a557294b1 --- /dev/null +++ b/docs/Functor.md @@ -0,0 +1,26 @@ +Functor +======= + +```haskell +foreach :: Functor f => f a -> (a -> b) -> f b +``` + +```haskell +map :: Functor f => (a -> b) -> f a -> f b +``` + +```haskell +($>) :: Functor f => f a -> b -> f b +``` + +```haskell +(<$>) :: Functor f => (a -> b) -> f a -> f b +``` + +```haskell +(<<$>>) :: (Functor f, Functor g) => (a -> b) -> f (g a) -> f (g b) +``` + +```haskell +void :: Functor f => f a -> f () +``` diff --git a/docs/List.md b/docs/List.md index 7c3b64ba6..fdc7b6442 100644 --- a/docs/List.md +++ b/docs/List.md @@ -109,7 +109,3 @@ filter :: (a -> Bool) -> [a] -> [a] ```haskell replicate :: Int -> a -> [a] ``` - -```haskell -map :: Functor f => (a -> b) -> f a -> f b -``` diff --git a/docs/Strings.md b/docs/Strings.md index 2f77d78b1..17f86d104 100644 --- a/docs/Strings.md +++ b/docs/Strings.md @@ -29,22 +29,32 @@ Encoding encodeUtf8 :: Text -> ByteString ``` +```haskell +> encodeUtf8 "ポケット" +"\227\131\157\227\130\177\227\131\131\227\131\136" +``` + #### decodeUtf8 ```haskell decodeUtf8 :: ByteString -> Text ``` +```haskell +> putStrLn $ decodeUtf8 "\227\131\157\227\130\177\227\131\131\227\131\136" +ポケット +``` + #### decodeUtf8' ```haskell -decodeUtf8' :: ByteString -> Text +decodeUtf8' :: ByteString -> Either UnicodeException Text ``` #### decodeUtf8With ```haskell -decodeUtf8With :: Data.Text.Encoding.Error.OnDecodeError -> ByteString -> Text +decodeUtf8With :: OnDecodeError -> ByteString -> Text ``` Conversion diff --git a/docs/index.rst b/docs/index.rst index 98aedfc9d..b195c6775 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -13,6 +13,7 @@ An alternative Prelude. Files Debug Bits + Functor Applicative Monad Maybe diff --git a/src/Protolude.hs b/src/Protolude.hs index c9d020d5c..8f2805523 100644 --- a/src/Protolude.hs +++ b/src/Protolude.hs @@ -352,6 +352,7 @@ import Data.Text.Encoding as X ( import Data.Text.Encoding.Error as X ( OnDecodeError , OnError + , UnicodeException , lenientDecode , strictDecode , ignore From c7eeb5349e8e690add8065b853c5a38052bbdd88 Mon Sep 17 00:00:00 2001 From: Stephen Diehl Date: Mon, 12 Dec 2016 16:10:49 +0000 Subject: [PATCH 14/24] fix exports for functor module --- src/Functor.hs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/Functor.hs b/src/Functor.hs index 80683396e..7d0a31d9f 100644 --- a/src/Functor.hs +++ b/src/Functor.hs @@ -6,9 +6,12 @@ module Functor ( Functor(..), ($>), (<$>), + (<<$>>), void, ) where +import Data.Function ((.)) + #if (__GLASGOW_HASKELL__ >= 710) import Data.Functor ( Functor(..) @@ -23,16 +26,17 @@ import Data.Functor ( ) import Data.Function (flip) -import Data.Function ((.)) infixl 4 $> ($>) :: Functor f => f a -> b -> f b ($>) = flip (<$) -(<<$>>) :: (Functor f, Functor g) => (a -> b) -> f (g a) -> f (g b) -(<<$>>) = fmap . fmap - void :: Functor f => f a -> f () void x = () <$ x #endif + +infixl 4 <<$>> + +(<<$>>) :: (Functor f, Functor g) => (a -> b) -> f (g a) -> f (g b) +(<<$>>) = fmap . fmap From d6d1004070ec7d8457b0a02c152676563ee6f911 Mon Sep 17 00:00:00 2001 From: Stephen Diehl Date: Mon, 12 Dec 2016 16:21:49 +0000 Subject: [PATCH 15/24] monoid module --- docs/Functor.md | 20 +++++++++++++++++--- docs/Monoid.md | 22 ++++++++++++++++++++++ 2 files changed, 39 insertions(+), 3 deletions(-) diff --git a/docs/Functor.md b/docs/Functor.md index a557294b1..44c441905 100644 --- a/docs/Functor.md +++ b/docs/Functor.md @@ -1,26 +1,40 @@ Functor ======= -```haskell -foreach :: Functor f => f a -> (a -> b) -> f b -``` +#### map ```haskell map :: Functor f => (a -> b) -> f a -> f b ``` +#### $> + ```haskell ($>) :: Functor f => f a -> b -> f b ``` +#### <$> + ```haskell (<$>) :: Functor f => (a -> b) -> f a -> f b ``` +#### <<$>> + ```haskell (<<$>>) :: (Functor f, Functor g) => (a -> b) -> f (g a) -> f (g b) ``` +#### void + ```haskell void :: Functor f => f a -> f () ``` + +#### foreach + +```haskell +foreach :: Functor f => f a -> (a -> b) -> f b +``` + + diff --git a/docs/Monoid.md b/docs/Monoid.md index fbe4c7956..41c362487 100644 --- a/docs/Monoid.md +++ b/docs/Monoid.md @@ -4,6 +4,28 @@ Monoid Monoid ------ +#### mempty + +```haskell +mempty :: Monoid a => a +``` + +#### <> + +```haskell +(<>) :: Monoid m => m -> m -> m +``` + +```haskell +mappend :: Monoid a => a -> a -> a +``` + +#### mconcat + +```haskell +mconcat :: Monoid a => [a] -> a +``` + Semigroup --------- From 0fb7730b0c540c1be28cc18601a39cea50677eb7 Mon Sep 17 00:00:00 2001 From: Stephen Diehl Date: Mon, 12 Dec 2016 16:30:52 +0000 Subject: [PATCH 16/24] expand semigroup --- docs/Monoid.md | 14 ++++++++++++++ src/Protolude.hs | 4 ++++ 2 files changed, 18 insertions(+) diff --git a/docs/Monoid.md b/docs/Monoid.md index 41c362487..c9aa00622 100644 --- a/docs/Monoid.md +++ b/docs/Monoid.md @@ -29,6 +29,17 @@ mconcat :: Monoid a => [a] -> a Semigroup --------- +```haskell +(<>) :: Semigroup a => a -> a -> a +``` + +```haskell +sconcat :: Semigroup a => NonEmpty a -> a +``` + +```haskell +stimes :: (Semigroup a, Integral b) => b -> a -> a +``` ```haskell option :: b -> (a -> b) -> Option a -> b @@ -57,3 +68,6 @@ stimesIdempotentMonoid :: (Integral b, Monoid a) => b -> a -> a ```haskell mtimesDefault :: (Integral b, Monoid a) => b -> a -> a ``` + +NonEmpty +--------- diff --git a/src/Protolude.hs b/src/Protolude.hs index 8f2805523..1cb87e2ad 100644 --- a/src/Protolude.hs +++ b/src/Protolude.hs @@ -103,6 +103,10 @@ import Data.Functor.Identity as X #if ( __GLASGOW_HASKELL__ >= 800 ) import Data.Monoid as X +import Data.List.NonEmpty as X ( + NonEmpty(..) + , nonEmpty + ) import Data.Semigroup as X ( Semigroup(sconcat, stimes) , WrappedMonoid From cc0565112fa3cb380be4435083b823a9e6b031ab Mon Sep 17 00:00:00 2001 From: Stephen Diehl Date: Tue, 13 Dec 2016 09:14:39 +0000 Subject: [PATCH 17/24] monoid and fold rearranging --- docs/Folds.md | 9 +++++++++ docs/List.md | 11 +++++++++++ docs/Monoid.md | 6 ++++++ src/Protolude.hs | 1 + 4 files changed, 27 insertions(+) diff --git a/docs/Folds.md b/docs/Folds.md index 0e3147218..80f579121 100644 --- a/docs/Folds.md +++ b/docs/Folds.md @@ -160,3 +160,12 @@ notElem :: (Foldable t, Eq a) => a -> t a -> Bool ```haskell find :: Foldable t => (a -> Bool) -> t a -> Maybe a ``` + + +```haskell +foldr1May :: (a -> a -> a) -> [a] -> Maybe a +``` + +```haskell +foldl1May :: (a -> a -> a) -> [a] -> Maybe a +``` diff --git a/docs/List.md b/docs/List.md index fdc7b6442..ad72c8cf8 100644 --- a/docs/List.md +++ b/docs/List.md @@ -109,3 +109,14 @@ filter :: (a -> Bool) -> [a] -> [a] ```haskell replicate :: Int -> a -> [a] ``` + +Indexing +-------- + +```haskell +atMay :: [a] -> Int -> Maybe a +``` + +```haskell +atDef :: a -> [a] -> Int -> a +``` diff --git a/docs/Monoid.md b/docs/Monoid.md index c9aa00622..55b8a68f2 100644 --- a/docs/Monoid.md +++ b/docs/Monoid.md @@ -29,14 +29,20 @@ mconcat :: Monoid a => [a] -> a Semigroup --------- +#### <> + ```haskell (<>) :: Semigroup a => a -> a -> a ``` +#### sconcat + ```haskell sconcat :: Semigroup a => NonEmpty a -> a ``` +#### stimes + ```haskell stimes :: (Semigroup a, Integral b) => b -> a -> a ``` diff --git a/src/Protolude.hs b/src/Protolude.hs index 1cb87e2ad..73892ba61 100644 --- a/src/Protolude.hs +++ b/src/Protolude.hs @@ -305,6 +305,7 @@ import Data.Function as X ( -- Genericss import GHC.Generics as X ( Generic(..) + , Generic1 , Rep , K1(..) , M1(..) From 1f2ed3e4cb3c4432ba97a6f8ca680c045fb94695 Mon Sep 17 00:00:00 2001 From: Stephen Diehl Date: Tue, 13 Dec 2016 12:31:47 +0000 Subject: [PATCH 18/24] fix lower bounds --- CHANGES.md | 1 + README.md | 4 ++-- src/Protolude.hs | 6 +++--- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 3cfe82cde..dcb35dcde 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -4,6 +4,7 @@ * Expose `Symbol` and `Nat` types from `GHC.TypeLits` by default. * Switch exported `(<>)` to be from `Data.Monoid` instead of Semigroup. * Expose `putByteString` and `putLByteString` monomorphic versions of `putStrLn` functions +* Export `ExceptT`, `ReaderT`, and `StateT` constructors. 0.1.9 ==== diff --git a/README.md b/README.md index 6569908ec..c12b2451a 100644 --- a/README.md +++ b/README.md @@ -92,9 +92,8 @@ tracks Stack LTS resolver. | Dependencies | Lower | Upper | | ----------- | -------- | -------- | | array | | 0.5 | -| async | 2.1 | 2.2 | +| async | 2.0 | 2.2 | | base | 4.6 | 4.10 | -| binary | | 0.7 | | bytestring | 0.10 | 0.11 | | containers | 0.5 | 0.6 | | deepseq | 1.3 | 1.5 | @@ -104,6 +103,7 @@ tracks Stack LTS resolver. | safe | 0.3 | 0.4 | | stm | 2.4 | 2.5 | | text | 1.2 | 1.3 | +| hashable | 1.2 | 1.3 | | transformers | 0.4 | 0.6 | FAQs diff --git a/src/Protolude.hs b/src/Protolude.hs index 73892ba61..d9c990949 100644 --- a/src/Protolude.hs +++ b/src/Protolude.hs @@ -223,7 +223,7 @@ import Data.Void as X ( import Control.Monad.State as X ( MonadState , State - , StateT + , StateT(StateT) , put , get , gets @@ -243,7 +243,7 @@ import Control.Monad.State as X ( import Control.Monad.Reader as X ( MonadReader , Reader - , ReaderT + , ReaderT(ReaderT) , ask , asks , local @@ -255,7 +255,7 @@ import Control.Monad.Reader as X ( import Control.Monad.Except as X ( MonadError , Except - , ExceptT + , ExceptT(ExceptT) , throwError , catchError , runExcept From ed6fa9c8ea8cf1e2f358667c6a42ea410fb867fb Mon Sep 17 00:00:00 2001 From: Stephen Diehl Date: Wed, 14 Dec 2016 17:16:20 +0000 Subject: [PATCH 19/24] refine monaderror section --- docs/Exceptions.md | 50 ++++++++++++++++++++++++++++++++++++++-------- src/Protolude.hs | 2 +- 2 files changed, 43 insertions(+), 9 deletions(-) diff --git a/docs/Exceptions.md b/docs/Exceptions.md index 88bd82f89..a5a1f137a 100644 --- a/docs/Exceptions.md +++ b/docs/Exceptions.md @@ -1,7 +1,8 @@ Exceptions ========== -#### MonadError +MonadError +---------- ```haskell class Monad m => MonadError e (m :: * -> *) | m -> e where @@ -9,34 +10,55 @@ class Monad m => MonadError e (m :: * -> *) | m -> e where catchError :: m a -> (e -> m a) -> m a ``` +#### Except + ```haskell type Except e = ExceptT e Identity ``` +*Example*: + +```haskell +``` + +#### ExceptT ```haskell newtype ExceptT e (m :: * -> *) a = Control.Monad.Trans.Except.ExceptT (m (Either e a)) ``` +*Example*: + +```haskell +``` + +#### throwError ```haskell throwError :: MonadError e m => e -> m a ``` +#### catchError + ```haskell catchError :: MonadError e m => m a -> (e -> m a) -> m a ``` +#### runExcept + ```haskell runExcept :: Except e a -> Either e a ``` +#### runExceptT + ```haskell runExceptT :: ExceptT e m a -> m (Either e a) ``` -#### Exceptions +Exceptions +---------- ```haskell class (Typeable e, Show e) => Exception e where @@ -45,42 +67,54 @@ class (Typeable e, Show e) => Exception e where GHC.Exception.displayException :: e -> String ``` +#### throwIO + ```haskell throwIO :: (MonadIO m, Exception e) => e -> m a ``` -```haskell -throwTo :: (MonadIO m, Exception e) => ThreadId -> e -> m () -``` +#### throwSTM ```haskell throwSTM :: Exception e => e -> STM a ``` +#### throwTo + ```haskell -throwError :: MonadError e m => e -> m a +throwTo :: (MonadIO m, Exception e) => ThreadId -> e -> m () ``` -#### Utilities +Utilities +--------- + +#### hush ```haskell hush :: Alternative m => Either e a -> m a ``` +#### note + ```haskell note :: (MonadError e m, Applicative m) => e -> Maybe a -> m a ``` +#### tryIO + ```haskell tryIO :: MonadIO m => IO a -> ExceptT IOException m a ``` -#### Fatal Errors +Fatal Errors +------------ ```haskell data FatalError = FatalError {msg :: Text} ``` +#### panic + ```haskell panic :: Text -> a ``` diff --git a/src/Protolude.hs b/src/Protolude.hs index d9c990949..eccb878cf 100644 --- a/src/Protolude.hs +++ b/src/Protolude.hs @@ -426,7 +426,7 @@ map :: Functor f => (a -> b) -> f a -> f b map = fmap uncons :: [a] -> Maybe (a, [a]) -uncons [] = Nothing +uncons [] = Nothing uncons (x:xs) = Just (x, xs) unsnoc :: [x] -> Maybe ([x],x) From 1140df0f912e8241470b88685917297f99791c30 Mon Sep 17 00:00:00 2001 From: Stephen Diehl Date: Thu, 15 Dec 2016 15:06:15 +0000 Subject: [PATCH 20/24] stub out rest of toc --- docs/Concurrency.md | 2 ++ docs/Reader.md | 2 ++ docs/ST.md | 2 ++ docs/State.md | 2 ++ docs/Transformers.md | 2 ++ docs/Traversals.md | 2 ++ docs/Unsafe.md | 2 ++ docs/index.rst | 3 +-- 8 files changed, 15 insertions(+), 2 deletions(-) create mode 100644 docs/Concurrency.md create mode 100644 docs/Reader.md create mode 100644 docs/ST.md create mode 100644 docs/State.md create mode 100644 docs/Transformers.md create mode 100644 docs/Traversals.md create mode 100644 docs/Unsafe.md diff --git a/docs/Concurrency.md b/docs/Concurrency.md new file mode 100644 index 000000000..92c552d0e --- /dev/null +++ b/docs/Concurrency.md @@ -0,0 +1,2 @@ +Concurrency +=========== diff --git a/docs/Reader.md b/docs/Reader.md new file mode 100644 index 000000000..b8c4c7e81 --- /dev/null +++ b/docs/Reader.md @@ -0,0 +1,2 @@ +Reader +====== diff --git a/docs/ST.md b/docs/ST.md new file mode 100644 index 000000000..2c23fbea4 --- /dev/null +++ b/docs/ST.md @@ -0,0 +1,2 @@ +ST +== diff --git a/docs/State.md b/docs/State.md new file mode 100644 index 000000000..b81674eed --- /dev/null +++ b/docs/State.md @@ -0,0 +1,2 @@ +State +===== diff --git a/docs/Transformers.md b/docs/Transformers.md new file mode 100644 index 000000000..90200db72 --- /dev/null +++ b/docs/Transformers.md @@ -0,0 +1,2 @@ +Transformers +============ diff --git a/docs/Traversals.md b/docs/Traversals.md new file mode 100644 index 000000000..31a1c1607 --- /dev/null +++ b/docs/Traversals.md @@ -0,0 +1,2 @@ +Traversals +========== diff --git a/docs/Unsafe.md b/docs/Unsafe.md new file mode 100644 index 000000000..24da25e38 --- /dev/null +++ b/docs/Unsafe.md @@ -0,0 +1,2 @@ +Unsafe +====== diff --git a/docs/index.rst b/docs/index.rst index b195c6775..b95e877bc 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -36,7 +36,7 @@ An alternative Prelude. Set Tuple Generics - Hashable + Hashing TypeLevel Unsafe @@ -44,5 +44,4 @@ Indices and tables ================== * :ref:`genindex` -* :ref:`modindex` * :ref:`search` From 5ce97cd0e997dc3a071ab49f49003c693f968ec7 Mon Sep 17 00:00:00 2001 From: Stephen Diehl Date: Thu, 15 Dec 2016 15:38:15 +0000 Subject: [PATCH 21/24] expand list processing functions --- docs/List.md | 48 ++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 42 insertions(+), 6 deletions(-) diff --git a/docs/List.md b/docs/List.md index ad72c8cf8..d70db3a19 100644 --- a/docs/List.md +++ b/docs/List.md @@ -4,46 +4,62 @@ List Slicing ------- +#### head + ```haskell head :: Foldable f => f a -> Maybe a ``` +#### tailMay + ```haskell tailMay :: [a] -> Maybe [a] ``` +#### tailSafe + ```haskell tailSafe :: [a] -> [a] ``` +#### initMay + ```haskell initMay :: [a] -> Maybe [a] ``` +#### initSafe + ```haskell initSafe :: [a] -> [a] ``` +#### initDef + ```haskell initDef :: [a] -> [a] -> [a] ``` +#### lastMay + ```haskell lastMay :: [a] -> Maybe a ``` +#### lastDef + ```haskell lastDef :: a -> [a] -> a ``` -```haskell -list :: [b] -> (a -> b) -> [a] -> [b] -``` +#### drop ```haskell drop :: Int -> [a] -> [a] ``` +#### take + ```haskell take :: Int -> [a] -> [a] ``` @@ -51,14 +67,20 @@ take :: Int -> [a] -> [a] Unpacking --------- +#### uncons + ```haskell uncons :: [a] -> Maybe (a, [a]) ``` +#### unsnoc + ```haskell unsnoc :: [x] -> Maybe ([x],x) ``` +#### unsnoc + ```haskell list :: [b] -> (a -> b) -> [a] -> [b] ``` @@ -66,6 +88,8 @@ list :: [b] -> (a -> b) -> [a] -> [b] Sorting --------- +#### sortOn + ```haskell sortOn :: Ord o => (a -> o) -> [a] -> [a] ``` @@ -73,6 +97,8 @@ sortOn :: Ord o => (a -> o) -> [a] -> [a] Removing --------- +#### ordNub + ```haskell ordNub :: Ord a => [a] -> [a] ``` @@ -80,14 +106,14 @@ ordNub :: Ord a => [a] -> [a] Splitting --------- -```haskell -splitAt :: Int -> [a] -> ([a], [a]) -``` +#### splitAt ```haskell splitAt :: Int -> [a] -> ([a], [a]) ``` +#### intercalate + ```haskell intercalate :: [a] -> [[a]] -> [a] ``` @@ -95,6 +121,8 @@ intercalate :: [a] -> [[a]] -> [a] Comparison --------- +#### isPrefixOf + ```haskell isPrefixOf :: Eq a => [a] -> [a] -> Bool ``` @@ -102,10 +130,14 @@ isPrefixOf :: Eq a => [a] -> [a] -> Bool Filtering --------- +#### filter + ```haskell filter :: (a -> Bool) -> [a] -> [a] ``` +#### replicate + ```haskell replicate :: Int -> a -> [a] ``` @@ -113,10 +145,14 @@ replicate :: Int -> a -> [a] Indexing -------- +#### atMay + ```haskell atMay :: [a] -> Int -> Maybe a ``` +#### atDef + ```haskell atDef :: a -> [a] -> Int -> a ``` From 33e412b59b4fbcbbd16a58e42c6b897c6cf708aa Mon Sep 17 00:00:00 2001 From: Stephen Diehl Date: Mon, 26 Dec 2016 17:49:43 +0000 Subject: [PATCH 22/24] bump license --- LICENSE | 2 +- README.md | 2 +- docs/List.md | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/LICENSE b/LICENSE index 4c9be4152..fd522c54c 100644 --- a/LICENSE +++ b/LICENSE @@ -1,4 +1,4 @@ -Copyright (c) 2016, Stephen Diehl +Copyright (c) 2016-2017, Stephen Diehl Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to diff --git a/README.md b/README.md index c12b2451a..128b71c9e 100644 --- a/README.md +++ b/README.md @@ -161,4 +161,4 @@ License ------- Released under the MIT License. -Copyright (c) 2016, Stephen Diehl +Copyright (c) 2016-2017, Stephen Diehl diff --git a/docs/List.md b/docs/List.md index d70db3a19..7c39f02b2 100644 --- a/docs/List.md +++ b/docs/List.md @@ -79,7 +79,7 @@ uncons :: [a] -> Maybe (a, [a]) unsnoc :: [x] -> Maybe ([x],x) ``` -#### unsnoc +#### list ```haskell list :: [b] -> (a -> b) -> [a] -> [b] From 254dafcb12e9d8867ca6c8f59bf9ae176730727b Mon Sep 17 00:00:00 2001 From: Stephen Diehl Date: Thu, 29 Dec 2016 19:46:57 +0000 Subject: [PATCH 23/24] basic examples --- docs/Exceptions.md | 6 ++++++ docs/Function.md | 39 +++++++++++++++++++++++++++++++++++++++ protolude.cabal | 2 +- 3 files changed, 46 insertions(+), 1 deletion(-) diff --git a/docs/Exceptions.md b/docs/Exceptions.md index a5a1f137a..ec0eae09c 100644 --- a/docs/Exceptions.md +++ b/docs/Exceptions.md @@ -118,3 +118,9 @@ data FatalError = FatalError {msg :: Text} ```haskell panic :: Text -> a ``` + +Terminate with an uncatchable fatal error. + +```haskell +> panic "Fatal error occured. +``` diff --git a/docs/Function.md b/docs/Function.md index 120377cc6..668591455 100644 --- a/docs/Function.md +++ b/docs/Function.md @@ -10,32 +10,66 @@ Composition ($) :: (a -> b) -> a -> b ``` +Infix form of function application. Applies a function from ``a → b`` to an +argument ``a``. + *Example*: +```haskell +> take 2 $ [1,2,3] +[1,2] +``` + #### . ```haskell (.) :: (b -> c) -> (a -> b) -> a -> c ``` +Function composition. Composes a function ``f`` (``b → c``) with a function +``g`` (``a → b``) yielding ``f ∘ g``. + *Example*: +```haskell +> map (negate . abs) [-1,0,1] +[-1,0,-1] +``` + #### & ```haskell (&) :: a -> (a -> b) -> b ``` +Flipped form of ``($)`` which applies an argument ``a`` to a function ``a → b``. + *Example*: +```haskell +> [1,2,3] & take 2 +[1,2] + +> replicate 10 3 & take 5 & tail +[3,3,3,3] +``` + #### flip ```haskell flip :: (a -> b -> c) -> b -> a -> c ``` +Flip takes a function of two arguments and returns a function taking the them in +reverse order. + *Example*: +```haskell +λ> flip take [1,2,3] 2 +[1,2] +``` + #### on ```haskell @@ -44,6 +78,11 @@ on :: (b -> b -> c) -> (a -> b) -> a -> a -> c *Example*: +```haskell +> sortBy (compare `on` fst) [(1,2), (3,4), (0,1)] +[(0,1),(1,2),(3,4)] +``` + #### const ```haskell diff --git a/protolude.cabal b/protolude.cabal index 3f84c0de1..c9cc2836f 100644 --- a/protolude.cabal +++ b/protolude.cabal @@ -1,5 +1,5 @@ name: protolude -version: 0.1.11 +version: 0.2 synopsis: A sensible set of defaults for writing custom Preludes. description: A sensible set of defaults for writing custom Preludes. homepage: https://github.com/sdiehl/protolude From 6d3940b4e58645fb76844e2511deefd604b5b0b3 Mon Sep 17 00:00:00 2001 From: Stephen Diehl Date: Sun, 1 Jan 2017 20:24:32 +0000 Subject: [PATCH 24/24] new difflog --- CHANGES.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGES.md b/CHANGES.md index dcb35dcde..baa49d5d1 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -5,6 +5,7 @@ * Switch exported `(<>)` to be from `Data.Monoid` instead of Semigroup. * Expose `putByteString` and `putLByteString` monomorphic versions of `putStrLn` functions * Export `ExceptT`, `ReaderT`, and `StateT` constructors. +* Export `NonEmpty` type and constructor for GHC 8.0. 0.1.9 ====