diff --git a/tamer/src/asg/air.rs b/tamer/src/asg/air.rs index 4e529b78..7373a362 100644 --- a/tamer/src/asg/air.rs +++ b/tamer/src/asg/air.rs @@ -36,7 +36,7 @@ use super::{ use crate::{ diagnose::Annotate, diagnostic_unreachable, - f::Functor, + f::Map, parse::{prelude::*, StateStack}, span::Span, sym::SymbolId, @@ -1310,7 +1310,7 @@ impl AsRef for EnvScopeKind { } } -impl Functor for EnvScopeKind { +impl Map for EnvScopeKind { type Target = EnvScopeKind; fn map(self, f: impl FnOnce(T) -> U) -> Self::Target { diff --git a/tamer/src/asg/air/expr.rs b/tamer/src/asg/air/expr.rs index 11b29ecd..5759e281 100644 --- a/tamer/src/asg/air/expr.rs +++ b/tamer/src/asg/air/expr.rs @@ -31,7 +31,7 @@ use super::{ }; use crate::{ asg::{graph::object::ObjectIndexTo, ObjectKind}, - f::Functor, + f::Map, parse::prelude::*, }; diff --git a/tamer/src/asg/graph.rs b/tamer/src/asg/graph.rs index 2dc7e9d6..62bd7c36 100644 --- a/tamer/src/asg/graph.rs +++ b/tamer/src/asg/graph.rs @@ -29,7 +29,7 @@ use self::object::{ use super::{AsgError, Object, ObjectIndex, ObjectKind}; use crate::{ diagnose::{panic::DiagnosticPanic, Annotate, AnnotatedSpan}, - f::Functor, + f::Map, global, span::Span, }; diff --git a/tamer/src/asg/graph/object.rs b/tamer/src/asg/graph/object.rs index 74199a18..32131fdb 100644 --- a/tamer/src/asg/graph/object.rs +++ b/tamer/src/asg/graph/object.rs @@ -123,7 +123,7 @@ use super::{Asg, AsgError}; use crate::{ diagnose::{panic::DiagnosticPanic, Annotate, AnnotatedSpan}, diagnostic_panic, - f::Functor, + f::Map, parse::util::SPair, span::{Span, UNKNOWN_SPAN}, }; @@ -924,7 +924,7 @@ impl ObjectIndex { } } -impl Functor for ObjectIndex { +impl Map for ObjectIndex { fn map(self, f: impl FnOnce(Span) -> Span) -> Self { match self { Self(index, span, ph) => Self(index, f(span), ph), diff --git a/tamer/src/asg/graph/object/expr.rs b/tamer/src/asg/graph/object/expr.rs index b2d1e86b..58a9f6fe 100644 --- a/tamer/src/asg/graph/object/expr.rs +++ b/tamer/src/asg/graph/object/expr.rs @@ -20,7 +20,7 @@ //! Expressions on the ASG. use super::{prelude::*, Doc, Ident, ObjectIndexTo, Tpl}; -use crate::{f::Functor, num::Dim, span::Span}; +use crate::{f::Map, num::Dim, span::Span}; use std::fmt::Display; #[cfg(doc)] @@ -52,7 +52,7 @@ impl Expr { } } -impl Functor for Expr { +impl Map for Expr { fn map(self, f: impl FnOnce(Span) -> Span) -> Self { match self { Self(op, dim, span) => Self(op, dim, f(span)), diff --git a/tamer/src/asg/graph/object/ident.rs b/tamer/src/asg/graph/object/ident.rs index 6ec4a6c8..bc4270a9 100644 --- a/tamer/src/asg/graph/object/ident.rs +++ b/tamer/src/asg/graph/object/ident.rs @@ -23,7 +23,7 @@ use super::{prelude::*, Expr, Meta, Pkg, Tpl}; use crate::{ diagnose::{panic::DiagnosticPanic, Annotate, Diagnostic}, diagnostic_todo, - f::Functor, + f::Map, fmt::{DisplayWrapper, TtQuote}, num::{Dim, Dtype}, parse::{util::SPair, Token}, diff --git a/tamer/src/asg/graph/object/meta.rs b/tamer/src/asg/graph/object/meta.rs index 15db6c60..5e56090c 100644 --- a/tamer/src/asg/graph/object/meta.rs +++ b/tamer/src/asg/graph/object/meta.rs @@ -36,7 +36,7 @@ use super::{prelude::*, Doc, Ident}; use crate::{ diagnose::Annotate, diagnostic_todo, - f::Functor, + f::Map, fmt::{DisplayWrapper, TtQuote}, parse::{util::SPair, Token}, span::Span, @@ -156,7 +156,7 @@ impl Display for Meta { } } -impl Functor for Meta { +impl Map for Meta { fn map(self, f: impl FnOnce(Span) -> Span) -> Self::Target { match self { Self::Required(span) => Self::Required(f(span)), diff --git a/tamer/src/asg/graph/object/pkg.rs b/tamer/src/asg/graph/object/pkg.rs index c07f5242..f64291a6 100644 --- a/tamer/src/asg/graph/object/pkg.rs +++ b/tamer/src/asg/graph/object/pkg.rs @@ -21,7 +21,7 @@ use super::{prelude::*, Doc, Ident, Tpl}; use crate::{ - f::Functor, + f::Map, fmt::{DisplayWrapper, TtQuote}, parse::{util::SPair, Token}, span::Span, @@ -87,7 +87,7 @@ impl Display for Pkg { } } -impl Functor for Pkg { +impl Map for Pkg { fn map(self, f: impl FnOnce(Span) -> Span) -> Self::Target { match self { Self(span, path) => Self(f(span), path), diff --git a/tamer/src/asg/graph/object/rel.rs b/tamer/src/asg/graph/object/rel.rs index 6a789422..41a7b2a8 100644 --- a/tamer/src/asg/graph/object/rel.rs +++ b/tamer/src/asg/graph/object/rel.rs @@ -30,7 +30,7 @@ use crate::{ graph::{object::Tpl, AsgRelMut}, Asg, AsgError, }, - f::Functor, + f::Map, span::Span, }; use std::{fmt::Display, marker::PhantomData}; @@ -481,7 +481,7 @@ impl DynObjectRel, ObjectIndex> { } } -impl Functor<(S, T), (U, V)> for DynObjectRel { +impl Map<(S, T), (U, V)> for DynObjectRel { type Target = DynObjectRel; fn map(self, f: impl FnOnce((S, T)) -> (U, V)) -> Self::Target { diff --git a/tamer/src/asg/graph/object/tpl.rs b/tamer/src/asg/graph/object/tpl.rs index 1e631ee5..b977e0b3 100644 --- a/tamer/src/asg/graph/object/tpl.rs +++ b/tamer/src/asg/graph/object/tpl.rs @@ -22,7 +22,7 @@ use std::fmt::Display; use super::{prelude::*, Doc, Expr, Ident}; -use crate::{f::Functor, parse::util::SPair, span::Span}; +use crate::{f::Map, parse::util::SPair, span::Span}; /// Template with associated name. #[derive(Debug, PartialEq, Eq)] @@ -46,7 +46,7 @@ impl Tpl { } } -impl Functor for Tpl { +impl Map for Tpl { fn map(self, f: impl FnOnce(Span) -> Span) -> Self::Target { match self { Self(span, shape) => Self(f(span), shape), @@ -54,7 +54,7 @@ impl Functor for Tpl { } } -impl Functor for Tpl { +impl Map for Tpl { fn map(self, f: impl FnOnce(TplShape) -> TplShape) -> Self::Target { match self { Self(span, shape) => Self(span, f(shape)), diff --git a/tamer/src/asg/graph/visit/ontree/test.rs b/tamer/src/asg/graph/visit/ontree/test.rs index 4b0443d3..f5dec397 100644 --- a/tamer/src/asg/graph/visit/ontree/test.rs +++ b/tamer/src/asg/graph/visit/ontree/test.rs @@ -24,7 +24,7 @@ use crate::{ graph::object::ObjectRelTy, ExprOp, }, - f::Functor, + f::Map, parse::{ util::{spair, SPair}, ParseState, diff --git a/tamer/src/f.rs b/tamer/src/f.rs index 7f82588c..be6d60a8 100644 --- a/tamer/src/f.rs +++ b/tamer/src/f.rs @@ -33,11 +33,12 @@ /// A type providing a `map` function from inner type `T` to `U`. /// -/// In an abuse of terminology, -/// this functor is polymorphic over the entire trait, +/// This used to be called `Functor`, +/// but was renamed because it was an abuse of terminology; +/// this is polymorphic over the entire trait, /// rather than just the definition of `map`, -/// allowing implementations to provide multiple specialized `map`s -/// without having to define individual `map_*` methods. +/// allowing implementations to provide multiple specialized `map`s +/// without having to define individual `map_*` methods. /// Rust will often be able to infer the proper types and invoke the /// intended `map` function within a given context, /// but methods may still be explicitly disambiguated using the @@ -46,16 +47,13 @@ /// if a functor requires a monomorphic function /// (so `T = U`), /// then it's not really a functor. -/// We'll refer to these structures informally as monomorphic functors, -/// since they provide the same type of API as a functor, -/// but cannot change the underlying type. /// /// This trait also provides a number of convenience methods that can be -/// implemented in terms of [`Functor::map`]. +/// implemented in terms of [`Map::map`]. /// /// Why a primitive `map` instead of `fmap`? /// ======================================== -/// One of the methods of this trait is [`Functor::fmap`], +/// One of the methods of this trait is [`Map::fmap`], /// which [is motivated by Haskell][haskell-functor]. /// This trait implements methods in terms of [`map`](Self::map) rather than /// [`fmap`](Self::fmap) because `map` is a familiar idiom in Rust and @@ -66,8 +64,8 @@ /// which is additional boilerplate relative to `map`. /// /// [haskell-functor]: https://hackage.haskell.org/package/base/docs/Data-Functor.html -pub trait Functor: Sized { - /// Type of object resulting from [`Functor::map`] operation. +pub trait Map: Sized { + /// Type of object resulting from [`Map::map`] operation. /// /// The term "target" originates from category theory, /// representing the codomain of the functor. @@ -83,7 +81,7 @@ pub trait Functor: Sized { /// all others are implemented in terms of it. fn map(self, f: impl FnOnce(T) -> U) -> Self::Target; - /// Curried form of [`Functor::map`], + /// Curried form of [`Map::map`], /// with arguments reversed. /// /// `fmap` returns a unary closure that accepts an object of type @@ -106,22 +104,22 @@ pub trait Functor: Sized { /// /// This is intended for cases where there's a single element that will /// be replaced, - /// taking advantage of [`Functor`]'s trait-level polymorphism. + /// taking advantage of [`Map`]'s trait-level polymorphism. fn overwrite(self, value: U) -> Self::Target { self.map(|_| value) } - /// Curried form of [`Functor::overwrite`], + /// Curried form of [`Map::overwrite`], /// with arguments reversed. fn foverwrite(value: U) -> impl FnOnce(Self) -> Self::Target { move |x| x.overwrite(value) } } -impl Functor for Option { +impl Map for Option { type Target = Option; - fn map(self, f: impl FnOnce(T) -> U) -> >::Target { + fn map(self, f: impl FnOnce(T) -> U) -> >::Target { Option::map(self, f) } } diff --git a/tamer/src/nir.rs b/tamer/src/nir.rs index 4040a008..50f165ef 100644 --- a/tamer/src/nir.rs +++ b/tamer/src/nir.rs @@ -57,7 +57,7 @@ mod tplshort; use crate::{ diagnose::{Annotate, Diagnostic}, - f::Functor, + f::Map, fmt::{DisplayWrapper, TtQuote}, parse::{util::SPair, Object, Token}, span::Span, @@ -228,7 +228,7 @@ impl Nir { } } -impl Functor for Nir { +impl Map for Nir { /// Map over a token's [`SymbolId`]. /// /// This allows modifying a token's [`SymbolId`] while retaining the diff --git a/tamer/src/nir/interp.rs b/tamer/src/nir/interp.rs index cc8d6bc8..0f476df8 100644 --- a/tamer/src/nir/interp.rs +++ b/tamer/src/nir/interp.rs @@ -108,7 +108,7 @@ use memchr::memchr2; use super::{Nir, NirEntity}; use crate::{ diagnose::{panic::DiagnosticPanic, Annotate, AnnotatedSpan, Diagnostic}, - f::Functor, + f::Map, fmt::{DisplayWrapper, TtQuote}, parse::{prelude::*, util::SPair, NoContext}, span::Span, diff --git a/tamer/src/parse/util.rs b/tamer/src/parse/util.rs index d22bda37..1aa53db5 100644 --- a/tamer/src/parse/util.rs +++ b/tamer/src/parse/util.rs @@ -26,7 +26,7 @@ //! to use outside of the domain of the parsing system itself. use super::{prelude::*, state::TransitionData}; -use crate::{f::Functor, span::Span, sym::SymbolId}; +use crate::{f::Map, span::Span, sym::SymbolId}; use std::fmt::Display; /// A [`SymbolId`] with a corresponding [`Span`]. @@ -83,7 +83,7 @@ impl SPair { } } -impl Functor for SPair { +impl Map for SPair { /// Map over the [`SymbolId`] of the pair while retaining the original /// associated [`Span`]. /// @@ -98,7 +98,7 @@ impl Functor for SPair { } } -impl Functor for SPair { +impl Map for SPair { /// Map over the [`Span`] of the pair while retaining the associated /// [`SymbolId`]. /// diff --git a/tamer/src/xir/autoclose.rs b/tamer/src/xir/autoclose.rs index f08dc6c8..08421ff7 100644 --- a/tamer/src/xir/autoclose.rs +++ b/tamer/src/xir/autoclose.rs @@ -101,7 +101,7 @@ use super::{ CloseSpan, OpenSpan, QName, }; use crate::{ - f::Functor, + f::Map, parse::prelude::*, span::{Span, UNKNOWN_SPAN}, xir::EleSpan, diff --git a/tamer/src/xir/flat.rs b/tamer/src/xir/flat.rs index ec01f04f..1b2ec2e4 100644 --- a/tamer/src/xir/flat.rs +++ b/tamer/src/xir/flat.rs @@ -46,7 +46,7 @@ use super::{ CloseSpan, OpenSpan, QName, Token as XirToken, TokenStream, }; use crate::{ - f::Functor, + f::Map, parse::prelude::*, span::Span, sym::{st::is_common_whitespace, GlobalSymbolResolve, SymbolId}, @@ -248,7 +248,7 @@ impl From for XirfToken { } } -impl Functor for XirfToken { +impl Map for XirfToken { fn map(self, f: impl FnOnce(Depth) -> Depth) -> Self::Target { use XirfToken::*;