on master help sign in
add missing example
commit2eeacc34c1cf59e99e5f569d9fd66b614442e58b authormax ulidtko <ulidtko@gmail.com> dateSat 9 May 2015, 01:46 (11 years ago) parent2130968
1 file changed+22
docs/tutorial/modules.rst+22
docs/tutorial/modules.rst+22
@@ -128,6 +128,28 @@ functions to be exported as ``abstract``, as we see below:
128128Finally, the default export mode can be changed with the ``%access``
129129directive, for example:
130130
131+.. code-block:: idris
132+
133+ module Btree
134+
135+ %access abstract
136+
137+ data BTree a = Leaf
138+ | Node (BTree a) a (BTree a)
139+
140+ insert : Ord a => a -> BTree a -> BTree a
141+ insert x Leaf = Node Leaf x Leaf
142+ insert x (Node l v r) = if (x < v) then (Node (insert x l) v r)
143+ else (Node l v (insert x r))
144+
145+ toList : BTree a -> List a
146+ toList Leaf = []
147+ toList (Node l v r) = btree.toList l ++ (v :: btree.toList r)
148+
149+ toTree : Ord a => List a -> BTree a
150+ toTree [] = Leaf
151+ toTree (x :: xs) = insert x (toTree xs)
152+
131153In this case, any function with no access modifier will be exported as
132154``abstract``, rather than left ``private``.
133155