Skip to content

Commit 39ecccd

Browse files
committed
ENH: added theory and model
1 parent 060fc8b commit 39ecccd

File tree

2 files changed

+59
-2
lines changed

2 files changed

+59
-2
lines changed

packages/catlog/src/stdlib/models.rs

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//! Standard library of models of double theories.
22
33
use std::rc::Rc;
4-
use ustr::{Ustr, ustr};
4+
use ustr::{ustr, Ustr};
55

66
use crate::dbl::{model::*, theory::*};
77
use crate::one::Path;
@@ -141,6 +141,41 @@ pub fn catalyzed_reaction(th: Rc<UstrModalDblTheory>) -> UstrModalDblModel {
141141
model
142142
}
143143

144+
/**
145+
*/
146+
pub fn water(th: Rc<UstrModalDblTheory>) -> UstrModalDblModel {
147+
let (state_type, aux_type) =
148+
(ModalObType::new(ustr("State")), ModalObType::new(ustr("Auxiliary")));
149+
let mut model = UstrModalDblModel::new(th);
150+
let (water, container) = (ustr("water"), ustr("container"));
151+
model.add_ob(water, state_type.clone());
152+
model.add_ob(container, state_type.clone());
153+
let (bwater, bcontainer) = (ustr("&water"), ustr("&container"));
154+
model.add_ob(bwater, aux_type.clone());
155+
model.add_ob(bcontainer, aux_type);
156+
let borrow = ModalMorType::One(ModeApp::new(ustr("borrow")));
157+
model.add_mor(
158+
ustr("borrow1"),
159+
ModalOb::Generator(water),
160+
ModalOb::Generator(bwater),
161+
borrow.clone(),
162+
);
163+
model.add_mor(
164+
ustr("borrow2"),
165+
ModalOb::Generator(container),
166+
ModalOb::Generator(bcontainer),
167+
borrow,
168+
);
169+
let (comparator, comparator_out) = (ustr("comparator"), ustr("comparator_out"));
170+
model.add_mor(
171+
comparator,
172+
ModalOb::List(List::Plain, vec![bwater.into(), bcontainer.into()]).into(),
173+
ModalOb::Generator(comparator_out),
174+
ModalMorType::One(ModeApp::new(ustr("function"))),
175+
);
176+
model
177+
}
178+
144179
#[cfg(test)]
145180
mod tests {
146181
use super::super::theories::*;

packages/catlog/src/stdlib/theories.rs

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
use ustr::ustr;
44

55
use crate::dbl::theory::*;
6-
use crate::one::{Path, fp_category::UstrFpCategory};
6+
use crate::one::{fp_category::UstrFpCategory, Path};
77

88
/** The empty theory, which has a single model, the empty model.
99
@@ -151,6 +151,11 @@ pub fn th_sym_monoidal_category() -> UstrModalDblTheory {
151151
th_list_algebra(List::Symmetric)
152152
}
153153

154+
///
155+
pub fn th_modal_state_aux() -> UstrModalDblTheory {
156+
th_modal_sf(List::Plain)
157+
}
158+
154159
/** The theory of a strict algebra of a list monad.
155160
156161
This is a modal double theory, parametric over which variant of the double list
@@ -194,6 +199,22 @@ fn th_list_lax_algebra(list: List) -> UstrModalDblTheory {
194199
th
195200
}
196201

202+
///
203+
fn th_modal_sf(list: List) -> UstrModalDblTheory {
204+
let m = Modality::List(list);
205+
let mut th: UstrModalDblTheory = Default::default();
206+
let (state, aux) = (ustr("State"), ustr("Auxiliary"));
207+
th.add_ob_type(state);
208+
th.add_ob_type(aux);
209+
let function = ustr("function");
210+
th.add_mor_type(function, ModeApp::new(aux).apply(m), ModeApp::new(aux));
211+
let (borrow, outpos, outneg) = (ustr("borrow"), ustr("out-pos"), ustr("out-neg"));
212+
th.add_mor_type(borrow, ModeApp::new(state), ModeApp::new(aux));
213+
th.add_mor_type(outpos, ModeApp::new(aux), ModeApp::new(state));
214+
th.add_mor_type(outneg, ModeApp::new(aux), ModeApp::new(state));
215+
th
216+
}
217+
197218
#[cfg(test)]
198219
mod tests {
199220
use super::*;
@@ -221,6 +242,7 @@ mod tests {
221242
fn validate_modal_theories() {
222243
assert!(th_monoidal_category().validate().is_ok());
223244
assert!(th_lax_monoidal_category().validate().is_ok());
245+
assert!(th_modal_state_aux().validate().is_ok());
224246
}
225247

226248
#[test]

0 commit comments

Comments
 (0)