From 080757cdadd3e8e3ed54eb3dee776669a558aa6e Mon Sep 17 00:00:00 2001 From: timofey Date: Wed, 3 May 2023 12:05:48 +0000 Subject: [PATCH] migrate the book --- .gitmodules | 4 ++ book-monads | 1 + book/.gitignore | 1 - book/book.toml | 16 ----- book/src/SUMMARY.md | 12 ---- book/src/ch00/s00-introduction.md | 1 - book/src/ch01/s00-background.md | 1 - book/src/ch02/s00-implementation.md | 1 - book/src/ch04/s00-concerns.md | 19 ------ book/src/ch04/s01-alternatives.md | 97 ----------------------------- book/src/ch04/s02-lifetimes.md | 18 ------ book/src/ch04/s03-stackless.md | 5 -- book/src/ch04/s04-covariance.md | 5 -- 13 files changed, 5 insertions(+), 176 deletions(-) create mode 100644 .gitmodules create mode 160000 book-monads delete mode 100644 book/.gitignore delete mode 100644 book/book.toml delete mode 100644 book/src/SUMMARY.md delete mode 100644 book/src/ch00/s00-introduction.md delete mode 100644 book/src/ch01/s00-background.md delete mode 100644 book/src/ch02/s00-implementation.md delete mode 100644 book/src/ch04/s00-concerns.md delete mode 100644 book/src/ch04/s01-alternatives.md delete mode 100644 book/src/ch04/s02-lifetimes.md delete mode 100644 book/src/ch04/s03-stackless.md delete mode 100644 book/src/ch04/s04-covariance.md diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..97a1b78 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,4 @@ +[submodule "book-monads"] + path = book-monads + url = https://gitea.parrrate.ru/PTV/book-monads.git + branch = latest diff --git a/book-monads b/book-monads new file mode 160000 index 0000000..ec6b0dc --- /dev/null +++ b/book-monads @@ -0,0 +1 @@ +Subproject commit ec6b0dcf5aa9ae47ec28bd5db959811d23102904 diff --git a/book/.gitignore b/book/.gitignore deleted file mode 100644 index 7585238..0000000 --- a/book/.gitignore +++ /dev/null @@ -1 +0,0 @@ -book diff --git a/book/book.toml b/book/book.toml deleted file mode 100644 index caea406..0000000 --- a/book/book.toml +++ /dev/null @@ -1,16 +0,0 @@ -[book] -authors = ["Alisa Feistel"] -language = "en" -multilingual = false -src = "src" -title = "Monads in Rust" - -[build] -build-dir = "book" -create-missing = false - -[output.html] -default-theme = "navy" -mathjax-support = true -git-repository-url = "https://gitea.parrrate.ru/PTV/radn-rs" -edit-url-template = "https://gitea.parrrate.ru/PTV/radn-rs/_edit/main/book/{path}" diff --git a/book/src/SUMMARY.md b/book/src/SUMMARY.md deleted file mode 100644 index 0f6afcf..0000000 --- a/book/src/SUMMARY.md +++ /dev/null @@ -1,12 +0,0 @@ -# Summary - -[Introduction](./ch00/s00-introduction.md) - -- [Background](./ch01/s00-background.md) -- [Implementation](./ch02/s00-implementation.md) -- [Usage]() -- [Current Implementation Concerns](./ch04/s00-concerns.md) - - [Alternative Monad Traits](./ch04/s01-alternatives.md) - - [Lifetimes](./ch04/s02-lifetimes.md) - - [Stackless](./ch04/s03-stackless.md) - - [Covariance](./ch04/s04-covariance.md) diff --git a/book/src/ch00/s00-introduction.md b/book/src/ch00/s00-introduction.md deleted file mode 100644 index e10b99d..0000000 --- a/book/src/ch00/s00-introduction.md +++ /dev/null @@ -1 +0,0 @@ -# Introduction diff --git a/book/src/ch01/s00-background.md b/book/src/ch01/s00-background.md deleted file mode 100644 index 5767328..0000000 --- a/book/src/ch01/s00-background.md +++ /dev/null @@ -1 +0,0 @@ -# Background diff --git a/book/src/ch02/s00-implementation.md b/book/src/ch02/s00-implementation.md deleted file mode 100644 index d2557ff..0000000 --- a/book/src/ch02/s00-implementation.md +++ /dev/null @@ -1 +0,0 @@ -# Implementation diff --git a/book/src/ch04/s00-concerns.md b/book/src/ch04/s00-concerns.md deleted file mode 100644 index 146cac8..0000000 --- a/book/src/ch04/s00-concerns.md +++ /dev/null @@ -1,19 +0,0 @@ -# Concerns (questions) with the current implementaion - -## There exist alternative `Functor` implementations - -See the [relevant subchapter](s01-alternatives.md) - -## It might be better to have a per-lifetime trait for `Functor`s - -See the [relevant subchapter](s02-lifetimes.md) - -## `Stackless` is kind of bad - -See the [relevant subchapter](s03-stackless.md) - -## `WeakFunctor::F<'a, A>` is not (yet) covariant over the lifetime `'a` - -See the [relevant subchapter](s04-covariance.md) - -## Can `WeakFunctor` be an associated type of a `Functor` instead of its supertype? diff --git a/book/src/ch04/s01-alternatives.md b/book/src/ch04/s01-alternatives.md deleted file mode 100644 index 735e65b..0000000 --- a/book/src/ch04/s01-alternatives.md +++ /dev/null @@ -1,97 +0,0 @@ -# Atlernatives to `Functor` trait - -## `_`-`FnOnce` category functors (current) - -Copied for reference. All following examples are in the same `Functor`-`Applicative`-`Monad` format -without extra (sub)traits like `WeakFunctor`, `Pure`, `ApplicativeLA2`, etc. . - -```rust -trait Functor { - type F<'a, A: 'a>: 'a - where - Self: 'a; - - fn fmap<'a, A: 'a, B: 'a>( - f: impl 'a + FnOnce(A) -> B, fa: Self::F<'a, A>, - ) -> Self::F<'a, B> - where - Self: 'a; -} - -fn fmap<'a, T: 'a + Functor, A: 'a, B: 'a>( - f: impl 'a + FnOnce(A) -> B, -) -> impl FnOnce(T::F<'a, A>) -> T::F<'a, B> { - |fa| T::fmap(f, fa) -} -``` - -## `Clone`-`Fn` category functors - -This is probably the closest representation to what Haskell views as a category of its types. - -```rust -trait Functor: Clone { - type F<'a, A: 'a + Clone>: 'a + Clone - where - Self: 'a; - - fn fmap<'a, A: 'a + Clone, B: 'a + Clone>( - f: impl 'a + Clone + Fn(A) -> B, fa: Self::F<'a, A>, - ) -> Self::F<'a, B> - where - Self: 'a; -} - -fn fmap<'a, T: 'a + Functor, A: 'a + Clone, B: 'a + Clone>( - f: impl 'a + Clone + Fn(A) -> B, -) -> impl 'a + Clone + Fn(T::F<'a, A>) -> T::F<'a, B> { - move |fa| T::fmap(f.clone(), fa) -} -``` - -## `Clone`-`FnMut` category functors - -We view use of `FnMut` for category's morphisms as somewhat controversial[^e]. -* Use of direct/indirect mutable references is, arguably, counter-functional[^e]. -* `Clone+FnMut` is, generally, nonsensical[^e]. -* Due to that, morphisms category isn't a subcategory, so can't be wrapped. -* Not being to wrap morphisms makes implementation of one specific `Applicative` method, -sequential application (`<*>` in Haskell, `seq` in RADN) *difficult*. - -```rust -trait Functor: Clone { - type F<'a, A: 'a + Clone>: 'a + Clone - where - Self: 'a; - - fn fmap<'a, A: 'a + Clone, B: 'a + Clone>( - f: impl 'a + FnMut(A) -> B, fa: Self::F<'a, A>, - ) -> Self::F<'a, B> - where - Self: 'a; -} -``` - -[^e]: elaborate? - -## `Copy`-`Fn` category functors - -```rust -trait Functor: Copy { - type F<'a, A: 'a + Copy>: 'a + Copy - where - Self: 'a; - - fn fmap<'a, A: 'a + Copy, B: 'a + Copy>( - f: impl 'a + Copy + Fn(A) -> B, fa: Self::F<'a, A>, - ) -> Self::F<'a, B> - where - Self: 'a; -} - -fn fmap<'a, T: 'a + Functor, A: 'a + Copy, B: 'a + Copy>( - f: impl 'a + Copy + Fn(A) -> B, -) -> impl 'a + Copy + Fn(T::F<'a, A>) -> T::F<'a, B> { - move |fa| T::fmap(f, fa) -} -``` diff --git a/book/src/ch04/s02-lifetimes.md b/book/src/ch04/s02-lifetimes.md deleted file mode 100644 index 0ff255b..0000000 --- a/book/src/ch04/s02-lifetimes.md +++ /dev/null @@ -1,18 +0,0 @@ -# Making lifetimes a parameter of a trait instead of that of the GAT - -Current: -```rust -pub trait WeakFunctor { - type F<'a, A: 'a>: 'a - where - Self: 'a; -} -``` - -Proposed: -```rust -pub trait WeakFunctor<'a>: 'a { - type F: 'a; -} -``` - diff --git a/book/src/ch04/s03-stackless.md b/book/src/ch04/s03-stackless.md deleted file mode 100644 index ee7c427..0000000 --- a/book/src/ch04/s03-stackless.md +++ /dev/null @@ -1,5 +0,0 @@ -# `Stackless<'a>` isn't covariant - -Current hypothesis is that this comes from `EvalTree<'a>` being invariant over `'a` -due to `FnOnce` being invariant over its output, -which in turn comes from present typesysten limitations. diff --git a/book/src/ch04/s04-covariance.md b/book/src/ch04/s04-covariance.md deleted file mode 100644 index 0cb0c7a..0000000 --- a/book/src/ch04/s04-covariance.md +++ /dev/null @@ -1,5 +0,0 @@ -## `CovariantFunctor` not (yet) included in `Monad` - -## Specific case: `Stackless<'a>` isn't covariant - -See the [relevant subchapter](s03-stackless.md)