A peer-to-peer stack for code collaboration
Documentation
Julian Arni886471670687
diff --git a/.gitignore b/.gitignoreindex bed8cbd..1906b9f 100644--- a/.gitignore+++ b/.gitignore@@ -12,3 +12,7 @@ out/result/result.stack-work/+docs/build/+*.orig+*.swp+docs/build/diff --git a/docs/Makefile b/docs/Makefilenew file mode 100644index 0000000..69fe55e--- /dev/null+++ b/docs/Makefile@@ -0,0 +1,19 @@+# Minimal makefile for Sphinx documentation+#++# You can set these variables from the command line.+SPHINXOPTS =+SPHINXBUILD = sphinx-build+SOURCEDIR = source+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)\ No newline at end of filediff --git a/docs/make.bat b/docs/make.batnew file mode 100644index 0000000..543c6b1--- /dev/null+++ b/docs/make.bat@@ -0,0 +1,35 @@+@ECHO OFF++pushd %~dp0++REM Command file for Sphinx documentation++if "%SPHINXBUILD%" == "" (+ set SPHINXBUILD=sphinx-build+)+set SOURCEDIR=source+set BUILDDIR=build++if "%1" == "" goto help++%SPHINXBUILD% >NUL 2>NUL+if errorlevel 9009 (+ echo.+ echo.The 'sphinx-build' command was not found. Make sure you have Sphinx+ echo.installed, then set the SPHINXBUILD environment variable to point+ echo.to the full path of the 'sphinx-build' executable. Alternatively you+ echo.may add the Sphinx directory to PATH.+ echo.+ echo.If you don't have Sphinx installed, grab it from+ echo.http://sphinx-doc.org/+ exit /b 1+)++%SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS%+goto end++:help+%SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS%++:end+popddiff --git a/docs/requirements.txt b/docs/requirements.txtnew file mode 100644index 0000000..b69779c--- /dev/null+++ b/docs/requirements.txt@@ -0,0 +1,34 @@+alabaster==0.7.11+argh==0.26.2+Babel==2.6.0+backports-abc==0.5+certifi==2018.8.24+chardet==3.0.4+CommonMark==0.5.4+docutils==0.14+future==0.16.0+futures==3.1.1+idna==2.7+imagesize==1.1.0+Jinja2==2.10+livereload==2.5.2+MarkupSafe==1.0+packaging==18.0+pathtools==0.1.2+port-for==0.3.1+Pygments==2.2.0+pyparsing==2.2.1+pytz==2018.5+PyYAML==3.13+recommonmark==0.4.0+requests==2.19.1+singledispatch==3.4.0.3+six==1.11.0+snowballstemmer==1.2.1+Sphinx==1.8.1+sphinx-autobuild==0.7.1+sphinxcontrib-websupport==1.1.0+tornado==5.1.1+typing==3.6.6+urllib3==1.23+watchdog==0.9.0diff --git a/docs/source/conf.py b/docs/source/conf.pynew file mode 100644index 0000000..0bef581--- /dev/null+++ b/docs/source/conf.py@@ -0,0 +1,197 @@+# -*- coding: utf-8 -*-+#+# Configuration file for the Sphinx documentation builder.+#+# This file does only contain a selection of the most common options. For a+# full list see the documentation:+# http://www.sphinx-doc.org/en/master/config++# -- Path setup --------------------------------------------------------------++# 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('.'))++from recommonmark.parser import CommonMarkParser++# -- Project information -----------------------------------------------------++project = u'radicle'+copyright = u'2018, Monadic'+author = u'Monadic'++# The short X.Y version+version = u''+# The full version, including alpha/beta/rc tags+release = u''+++# -- 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.intersphinx',+ 'sphinx.ext.todo',+ 'sphinx.ext.coverage',+ 'sphinx.ext.mathjax',+ 'sphinx.ext.ifconfig',+ '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', '.lrad', '.md']++# The master toctree document.+master_doc = 'index'++# 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++# List of patterns, relative to source directory, that match files and+# directories to ignore when looking for source files.+# This pattern also affects html_static_path and html_extra_path.+exclude_patterns = []++# The name of the Pygments (syntax highlighting) style to use.+pygments_style = None+++# -- 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 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']++# Custom sidebar templates, must be a dictionary that maps document names+# to template names.+#+# The default sidebars (for documents that don't match any pattern) are+# defined by theme itself. Builtin themes are using these templates by+# default: ``['localtoc.html', 'relations.html', 'sourcelink.html',+# 'searchbox.html']``.+#+# html_sidebars = {}+++# -- Options for HTMLHelp output ---------------------------------------------++# Output file base name for HTML help builder.+htmlhelp_basename = 'radicledoc'+++# -- 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, 'radicle.tex', u'radicle Documentation',+ u'Monadic', 'manual'),+]+++# -- 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, 'radicle', u'radicle Documentation',+ [author], 1)+]+++# -- 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, 'radicle', u'radicle Documentation',+ author, 'radicle', 'One line description of project.',+ 'Miscellaneous'),+]+++# -- Options for Epub output -------------------------------------------------++# Bibliographic Dublin Core info.+epub_title = project++# The unique identifier of the text. This can be a ISBN number+# or the project homepage.+#+# epub_identifier = ''++# A unique identification for the text.+#+# epub_uid = ''++# A list of files that should not be packed into the epub file.+epub_exclude_files = ['search.html']+++# -- Extension configuration -------------------------------------------------++# -- Options for intersphinx extension ---------------------------------------++# Example configuration for intersphinx: refer to the Python standard library.+intersphinx_mapping = {'https://docs.python.org/': None}++# -- Options for todo extension ----------------------------------------------++# If true, `todo` and `todoList` produce output, else they produce nothing.+todo_include_todos = True++source_parsers = {+ '.lrad': CommonMarkParser,+}+diff --git a/docs/source/guide/Basics.lrad b/docs/source/guide/Basics.lradnew file mode 100644index 0000000..a3ee1b5--- /dev/null+++ b/docs/source/guide/Basics.lrad@@ -0,0 +1,242 @@+# Basics++Though `radicle` is designed with a particular use-case in mind--namely,+defining and interacting with the Open Source Network chains--it is ultimately a+general purpose language, quite similar to+[Scheme](en.wikipedia.org/wiki/Scheme_%28programming_language%29) or+[Clojure](clojure.org/). To effectively use it, it is helpful to learn the basics+of it independent of its application.++This chapter introduces `radicle` as a language. In each section we present+a core datatype of the language, and show some basic operations that can be+performed on them.++## Built-in datatypes++`radicle` supports the following datatypes:++### Booleans++The literal syntax for booleans is `#t` for true, and `#f` for false. Booleans can be combined with `and` and `or`:++```radicle+(and #t #f) ;; ==> #f+(or #t #f) ;; ==> #t+```++### Strings++Strings are enclosed in double quotes:++```radicle+"this is a string"+```++### Vectors++`radicle`'s *vectors* are an array-like container for values. Literal notation+for vectors uses square brackets:++```radicle+["this" "is" "a" "vector"]+```++You can access any of the elements in the vector using `nth`:++```radicle+(nth 2 ["start at zero!" "one" "two" "three"]) ;; ==> "two"+```++But be careful: if the size of the argument isn't less than (`<`) the size of the+vector then this will result in an error.++Concatenate vectors using `<>`:++```radicle+(<> [1 2 3] [4 5 6]) ;; ==> [1 2 3 4 5 6]+```++Add an element to the left using `add-left`:++```radicle+(add-left 0 [1 2 3]) ;; ==> [0 1 2 3]+```++Add an element to the right using `add-right`:++```radicle+(add-right 3 [0 1 2]) ;; ==> [0 1 2 3]+```++### Lists++Lists are one of the fundamental data structures of functional programming.+Just like vector are enclosed, list are enclosed in parentheses.++However, as you may have noticed, parentheses are also used for function+application. This is because lists are the representation for *code* that+evaluates to the result of applying the first element of the list to the+other elements.++Don't worry if this is still a little unclear; we will discuss it at greater+length when we talk about evaluation and quotation. For now, what this in+practice means is that if you want to create a list, you can used the+function `list` on the elements you want in the list. You can also use+`list-from-vec` to make a vector into a list.++You can prepend an element to a list with `cons`:++```radicle+(cons 0 (list 1)) ;; ==> (0 1)+```++Retrieve the head of a list with `head`:++```radicle+(head (list 0 1 2 3)) ;; ==> 0+```++The rest of it with `tail`:++```radicle+(tail (list 0 1 2 3)) ;; ==> (1 2 3)+```++Or a specific index with `nth`:++```radicle+(nth 2 (list 0 1 2 3)) ;; ==> 2+```++### Lists or vectors?++Vectors differ from lists in a couple of important ways. First, lists are+implemented as linked lists, and therefore have accessing the `nth` element+of a list has a linear on `n` (the function `nth` works for both vectors and+lists). Additionally, appending to the end of a list is also linear. Vectors,+on the other hand, allow for faster (logarithmic) indexed access and appending+(constant time).++### Dictionaries++Dictionaries are mappings between keys and values. (You may know them as maps,+associative arrays, or symbol tables.) Literal syntax for dictionaries is+formed by including the keys and values inside curly braces:++```radicle+{ :key1 1+ :key2 "foo"+}+```++It is an error to have an odd number of elements inside the braces.++Keys may be any value, including other dictionaries:++```radicle+{ :key1 1+ { :nested "foo" } "bar"+}+```++You can access the value associated with a key with the function `lookup`:++```radicle+(lookup :key1 { :key1 1 }) ;; ==> 1+```++And add new values with `insert`:++```radicle+(insert :key2 2 { :key1 1 }) ==> { :key1 1 :key2 2 }+```++## Simple expressions++### Branching++To dispatch on a boolean value use `if`:++```radicle+(if (pr-accepted? pr)+ (merge-pr master pr)+ (close-pr pr))+```++To test multiple booleans use `cond`:++```radicle+(cond+ (> num-issues 100) "Oh no, so many bugs!"+ (= num-issues 0) "All done!"+ #t "A few bugs.")+```++In fact _all_ values which are not `#f` are treated as true, so one can also+write:++```radicle+(cond+ (> num-issues 100) "Oh no, so many bugs!"+ (= num-issues 0) "All done!"+ :else "A few bugs.")+```++If none of the conditions in the `cond` are true then the result is an error!++### Function application++A function call takes prefixed, parenthesized form. That is, the call appears+within parenthesis, with the function at the head, followed by its arguments:++```radicle+(+ 3 2) ;; => 5+```++### Definitions++Definitions bind values to an identifier.++```radicle+(def five 5)+five ;; ==> 5+```++### Functions++A function is created using `fn`. The first argument is a vector of symbols+representing the parameters of the function, and the rest is a sequence of+expressions which are run when the function is called.++So a function which adds one to a number can be defined like so:+```radicle+(fn [x] (+ x 1))+```++You can call it like any other function:+```radicle+((fn [x] (+ x 1)) 1) ;; ==> 2+```++But most likely you want to `def`ine a new variable:+```radicle+(def f (fn [x] (+ x 1)))++(f 41) ;; ==> 42+```++Functions are not by default recursive. If you want to define a recursive+function, use the `def-rec` form:++```radicle+(def-rec range+ (fn [from to]+ (if (<= to from)+ (list)+ (cons from (range (+ 1 from) to)))))+```++Note that `def-rec` may only be used to define functions.++## Quote and eval+diff --git a/docs/source/guide/Chains.lrad b/docs/source/guide/Chains.lradnew file mode 100644index 0000000..22a644d--- /dev/null+++ b/docs/source/guide/Chains.lrad@@ -0,0 +1,20 @@+# Chains++By now you've seen some of `radicle`, but we haven't touched upon what makes it+different from other languages.++## The execution context++The most familiar way to think about a program execution is as happening on one+particular machine. *Which* machine that is often matters to understanding how+the program behaves; a program might after all read from a file, for example,+and behave differently based on whether that file exists, and what it's+contents are. But other machines may not have that file, or have one that+differs in some way.++This aspect of program execution is often a source of headache for developers,+as it leads to hard-to-reproduce or -predict behavior. But--and more+importantly for our purposes--it also means we can't think of programs in the+abstract++In other words, we would like for programs to be *deterministic*.diff --git a/docs/source/guide/GettingStarted.rst b/docs/source/guide/GettingStarted.rstnew file mode 100644index 0000000..c5a6910--- /dev/null+++ b/docs/source/guide/GettingStarted.rst@@ -0,0 +1,46 @@+Getting Started+==================++The easiest way to play with `radicle` is to use the online REPL, available at+the `radicle` website_.++.. _website: http://radicle.xyz++The online REPL is quite limited, however (and slow). So you will probably also+want the `radicle` executable.++Building from source+----------------------++In order to build from source, you'll need stack_:++.. _stack: https://docs.haskellstack.org/en/stable/README/++.. code-block:: bash++ curl -sSL https://get.haskellstack.org/ | sh++You can then download and build the latest source code for `radicle` from+http://git.oscoin.io/radicle:++.. code-block:: bash++ git clone http://git.oscoin.io/radicle+ cd radicle+ stack build+ stack install++You can test that `radicle` was properly installed by running:++.. code-block:: bash++ radicle --help++Note that the `radicle` executable always takes a file as an argument. If you+want to run it interactively (i.e., as a REPL), you'll need to pass it the REPL+file (included in the repository):+++.. code-block:: bash++ radicle --config rad/repl.raddiff --git a/docs/source/guide/index.rst b/docs/source/guide/index.rstnew file mode 100644index 0000000..874a99c--- /dev/null+++ b/docs/source/guide/index.rst@@ -0,0 +1,60 @@+The radicle guide+==================++radicle is a language for building and interacting with chains of the Open+Source Network. What these chains do--how they behave--is entirely up to you.++This guide provides an introduction to radicle--as a language, as a tool for+building chains, and as a means of interacting with existing chains.+++An example+------------++As a running example, we'll create a chain for managing the issues of a+repository. We'll see how to define the format of issues that can be created;+how to define rights and permissions for certain types of interaction; and+how to allow for future changes to the chain.++::++ (load! "rad/prelude.rad")+ (def issues (ref { :open nil :closed nil }))+ (def system (ref {}))++ (def new-feature-request+ (fn [author description test-case]+ ...))++ (def new-bug-report+ (fn [author description test-case]+ ...))++ (def new-question+ (fn [author description]+ ...))++ (def close-issue ...)++ (def can-modify ...)++ (def modify-system ..)++ (write-ref system+ { :feature-handler new-feature-request+ :bug-handler new-bug-report+ :question-handler new-question+ :can-modify can-modify+ })+++ (def handle-input+ (fn [expr]+ ...))+++.. toctree::+ :maxdepth: 2++ GettingStarted.md+ Basics.lraddiff --git a/docs/source/index.rst b/docs/source/index.rstnew file mode 100644index 0000000..3d9039e--- /dev/null+++ b/docs/source/index.rst@@ -0,0 +1,23 @@+.. radicle documentation master file, created by+ sphinx-quickstart on Wed Sep 26 11:08:32 2018.+ You can adapt this file completely to your liking, but it should at least+ contain the root `toctree` directive.++radicle+===================================++.. toctree::+ :maxdepth: 3++ guide/index.rst+ guide/GettingStarted.rst+ guide/Basics.lrad++++Indices and tables+==================++* :ref:`genindex`+* :ref:`modindex`+* :ref:`search`diff --git a/exe/Doc.hs b/exe/Doc.hsnew file mode 100644index 0000000..8e993da--- /dev/null+++ b/exe/Doc.hs@@ -0,0 +1,42 @@+-- | This executable processes literate radicle files. It accepts Markdown, and+-- runs the code inside code blocks (within three backticks).+module Doc where++import Options.Applicative+import Protolude+import Radicle+import System.Console.Haskeline (defaultSettings, runInputT)+import Text.Pandoc++main :: IO ()+main = do+ opts' <- execParser allOpts+ run (srcFile opts')+ where+ allOpts = info (opts <**> helper)+ ( fullDesc+ <> progDesc "Radicle literate file tester"+ <> header "radlit"+ )++run :: FilePath -> IO ()+run f = do+ txt <- readFile f+ pand <- runIOorExplode $ readMarkdown def txt+ res <- runInputT defaultSettings $ runLang replBindings $ interpretMany (toS f) $ getCode pand+ case res of+ (Left err, _) -> die . toS $ "Error: " ++ show err+ _ -> pure ()++getCode :: Pandoc -> Text+getCode (Pandoc _ blocks)+ = toS $ mconcat [ content | CodeBlock attr content <- blocks, isRad attr ]+ where+ isRad (id, _, _) = id == "radicle"++newtype Opts = Opts+ { srcFile :: FilePath+ }++opts :: Parser Opts+opts = Opts <$> argument str (metavar "FILE")diff --git a/nix/shell.nix b/nix/shell.nixindex 167b4e7..e28dd83 100644--- a/nix/shell.nix+++ b/nix/shell.nix@@ -1,6 +1,7 @@{ pkgs ? import <nixpkgs> {}, compiler ? "ghc843"-, doc ? false+, doc ? true+, extras ? true}:with pkgs;@@ -13,10 +14,15 @@ instdenv.mkDerivation {name = "radicle-dev";buildInputs = [ ghc zlib python3 wget stack ]- ++ (if doc then [docstuffs postgresql] else []);+ ++ (if doc then [docstuffs postgresql] else [])+ ++ (if extras then [ vimPlugins.stylish-haskell haskellPackages.apply-refact hlint ] else []);libraryPkgconfigDepends = [ zlib ];shellHook = ''eval $(grep export ${ghc}/bin/ghc)export LD_LIBRARY_PATH=$PWD:$LD_LIBRARY_PATH;+ alias check="pushd $PWD && ./scripts/check-fmt.sh && hlint . && popd"+ alias mkdocs="pushd $PWD/docs && make html && popd"+ alias sb="stack build --system-ghc --nix-packages zlib"+ alias sb="stack test --fast --system-ghc --nix-packages zlib"'';}diff --git a/package.yaml b/package.yamlindex 08462a5..fde4a5d 100644--- a/package.yaml+++ b/package.yaml@@ -143,6 +143,19 @@ executables:buildable: falseghc-options: -main-is GHCJS -threaded+ doc:+ main: Doc.hs+ source-dirs: exe/+ other-modules: []+ when:+ - condition: impl(ghcjs)+ buildable: false+ dependencies:+ - radicle+ - optparse-applicative+ - pandoc+ ghc-options: -main-is Doc+default-extensions:- AutoDeriveTypeable- ConstraintKindsdiff --git a/scripts/build-docs.sh b/scripts/build-docs.shnew file mode 100755index 0000000..88495dc--- /dev/null+++ b/scripts/build-docs.sh@@ -0,0 +1,46 @@+#!/usr/bin/env bash++set -o nounset+set -o errexit++BUCKET="gs://docs.radicle.xyz"+IS_NIX=${NIX_PATH:-}++help(){+ echo "./build-docs.sh [-d|-h]"+ echo " Builds the radicle documentation"+ echo " Options:"+ echo " -h : Show this help text"+ exit 0+}++# Helper to prevent pushd/popd from printing stuff to the console+pushd () {+ command pushd "$@" > /dev/null+}++popd () {+ command popd "$@" > /dev/null+}++build(){+ pushd "$PWD"/docs+ [ -z "$IS_NIX" ] && pip install -r requirements.txt+ make html+ popd+}+++while getopts ":h" opt; do+ case $opt in+ h)+ help+ ;;+ \?)+ echo "Invalid option: -$OPTARG"+ help+ ;;+ esac+done++builddiff --git a/src/Radicle/Internal/Core.hs b/src/Radicle/Internal/Core.hsindex 40be7a2..1343f1b 100644--- a/src/Radicle/Internal/Core.hs+++ b/src/Radicle/Internal/Core.hs@@ -4,7 +4,7 @@-- | The core radicle datatypes and functionality.module Radicle.Internal.Core where-import Protolude hiding (Constructor, TypeError, list, (<>))+import Protolude hiding (Constructor, TypeError, (<>))import Codec.Serialise (Serialise)import Control.Monad.Exceptdiff --git a/src/Radicle/Internal/PrimFns.hs b/src/Radicle/Internal/PrimFns.hsindex 5baf87c..65c6461 100644--- a/src/Radicle/Internal/PrimFns.hs+++ b/src/Radicle/Internal/PrimFns.hs@@ -7,7 +7,7 @@ module Radicle.Internal.PrimFns, primFnsEnv) where-import Protolude hiding (TypeError, toList)+import Protolude hiding (TypeError)import qualified Data.Aeson as Aesonimport qualified Data.IntMap as IntMap