Skip to content

A peer-to-peer stack for code collaboration

Rebase, change encoding of Maybes

James Henri Haydon6c259125750c
diff --git a/docs/source/reference.rst b/docs/source/reference.rst
index ae8ebc2..1652ab5 100644
--- a/docs/source/reference.rst
+++ b/docs/source/reference.rst
@@ -740,13 +740,13 @@ right now, formatted according to ISO 8601.
Maybe
-----
-Optionality is represented using ``[:Just x]`` for when the value
-exists, and ``:Nothing`` when it doesn't.
+Optionality is represented using ``[:just x]`` for when the value
+exists, and ``:nothing`` when it doesn't.
``(/Just pat)``
~~~~~~~~~~~~~~~
-Pattern which matches ``[:Just x]``.
+Pattern which matches ``[:just x]``.
``(maybe->>= v f)``
~~~~~~~~~~~~~~~~~~~
diff --git a/exe/ReferenceDoc.hs b/exe/ReferenceDoc.hs
index 99932c3..a5fef14 100644
--- a/exe/ReferenceDoc.hs
+++ b/exe/ReferenceDoc.hs
@@ -61,7 +61,7 @@ main = do
, sec "Input/Output" io
"Effectful functions. These functions are not available in 'pure' chains, but are available in the local REPL."
, sec "Maybe" maybe'
- "Optionality is represented using `[:Just x]` for when the value exists, and `:Nothing` when it doesn't."
+ "Optionality is represented using `[:just x]` for when the value exists, and `:nothing` when it doesn't."
, sec "Lenses" lens
"Functional references into radicle values."
, sec "Validation" validation
diff --git a/rad/prelude/patterns.rad b/rad/prelude/patterns.rad
index 093166a..2d5641d 100644
--- a/rad/prelude/patterns.rad
+++ b/rad/prelude/patterns.rad
@@ -6,18 +6,18 @@
(fn [v f]
(if (vector? v)
(if (eq? (length v) 2)
- (if (eq? (nth 0 v) :Just)
+ (if (eq? (nth 0 v) :just)
(f (nth 1 v))
- :Nothing)
- :Nothing)
- :Nothing)))
+ :nothing)
+ :nothing)
+ :nothing)))
(def-rec maybe-foldlM
"Monadic fold over the elements of a seq, associating to the left (i.e. from
left to right) in the maybe monad."
(fn [f i xs]
(if (empty-seq? xs)
- [:Just i]
+ [:just i]
(maybe->>= (f i (nth 0 xs))
(fn [b] (maybe-foldlM f b (drop 1 xs)))))))
@@ -47,18 +47,18 @@
(def cs (lookup :conflicts excl-merge))
(def merge (lookup :merge excl-merge))
(if (eq? cs {})
- [:Just merge]
+ [:just merge]
(maybe-foldlM (fn [acc kv]
(def v (nth 1 kv))
(def v0 (nth 0 v))
(if (eq? v0 (nth 1 v))
- [:Just (insert (nth 0 kv) v0 acc)]
- :Nothing))
+ [:just (insert (nth 0 kv) v0 acc)]
+ :nothing))
merge
(seq cs)))))
(def _
"The wildcard pattern."
- (fn [v] [:Just {}]))
+ (fn [v] [:just {}]))
(def-rec match-pat
"The pattern matching dispatch function. This function defines how patterns
@@ -77,7 +77,7 @@
(fn [bs] (non-linear-merge acc bs))))
{}
(zip pats v))
- :Nothing))))
+ :nothing))))
(def /dict
(fn [keys-pat]
(fn [d]
@@ -88,14 +88,14 @@
(if (member? k d)
(maybe->>= (match-pat pat (lookup k d))
(fn [bs] (non-linear-merge acc bs)))
- :Nothing))
+ :nothing))
{}
(seq keys-pat)))))
(cond
(atom? pat)
- [:Just {pat v}]
+ [:just {pat v}]
(some [(number? pat) (keyword? pat) (string? pat)])
- (if (eq? pat v) [:Just {}] :Nothing)
+ (if (eq? pat v) [:just {}] :nothing)
(dict? pat)
((/dict pat) v)
(vector? pat)
@@ -121,15 +121,15 @@
['x 'y] :no) ==> :yes])
(def /Just
- "Pattern which matches `[:Just x]`."
+ "Pattern which matches `[:just x]`."
(fn [pat]
(fn [v]
(maybe->>= v
(fn [x] (match-pat pat x))))))
(:test "Just patterns"
- [ (match [:Just 42] (/Just 'x) x _ :no) ==> 42 ]
- [ (match :Nothing (/Just 'x) x _ :yes) ==> :yes ])
+ [ (match [:just 42] (/Just 'x) x _ :no) ==> 42 ]
+ [ (match :nothing (/Just 'x) x _ :yes) ==> :yes ])
(def /cons
"A pattern for lists with a head and a tail."
@@ -143,15 +143,15 @@
(maybe->>=
(match-pat xs-pat (tail v))
(fn [b2] (non-linear-merge b1 b2)))))
- :Nothing)
- :Nothing))))
+ :nothing)
+ :nothing))))
(def /nil
"Empty-list pattern."
(fn [v]
(if (eq? v (list))
- [:Just {}]
- :Nothing)))
+ [:just {}]
+ :nothing)))
(:test "List pattern matching"
[ (match (list) /nil :yes _ :no) ==> :yes ]
@@ -163,8 +163,8 @@
(fn [p]
(fn [v]
(if (p v)
- [:Just {}]
- :Nothing))))
+ [:just {}]
+ :nothing))))
(:test "Predicate patterns"
[ (match (list)
@@ -182,7 +182,7 @@
(if (atom? var)
(fn [v]
(maybe->>= (match-pat pat v)
- (fn [bs] [:Just (insert var v bs)])))
+ (fn [bs] [:just (insert var v bs)])))
(throw 'pattern-error "The first argument of `/as` should be an atom."))))
(:test "As-patterns work"
diff --git a/src/Radicle/Internal/Pretty.hs b/src/Radicle/Internal/Pretty.hs
index 3c47e0c..91b8f9d 100644
--- a/src/Radicle/Internal/Pretty.hs
+++ b/src/Radicle/Internal/Pretty.hs
@@ -78,8 +78,8 @@ instance Pretty r => Pretty (LangErrorData r) where
NoMatch -> "Pattern match(es) are non-exhaustive."
NoValue -> "The `match` special form must be given a value to match on."
BadBindings p -> "Faulty pattern function. Pattern functions must return\
- \ `[:Just b]` where `b` is a dict of new bindings (from\
- \ atoms to values), or `:Nothing`:" <+> pretty p
+ \ `[:just b]` where `b` is a dict of new bindings (from\
+ \ atoms to values), or `:nothing`:" <+> pretty p
-- | A fast and compact layout. Primarily intended for testing.