1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
//! Pure monadic computation - the core domain entity.
//!
//! This represents a computation that may have effects but expresses
//! them in a pure, mathematical way through monadic structures.
use crate::eval::{
Value, Environment,
operational_semantics::{EvaluationContext, ComputationState},
continuation_domain::{CapturedContinuation, ContinuationId},
};
use crate::ast::{Expr, Spanned};
use crate::diagnostics::{Result, Error, Span};
use crate::effects::{
Effect, EffectContext, Maybe, Either, IO, State, Reader,
ContinuationMonad, EffectfulComputation,
};
use std::rc::Rc;
use std::sync::Arc;
use std::collections::HashMap;
use async_trait::async_trait;
use super::monadic_transformation::MonadicTransformation;
/// Pure monadic computation - the core domain entity.
///
/// This represents a computation that may have effects but expresses
/// them in a pure, mathematical way through monadic structures.
#[derive(Debug, Clone)]
pub enum MonadicComputation<T: Clone> {
/// Pure value computation
Pure(T),
/// Continuation monad computation
Continuation(ContinuationMonad<T>),
/// Maybe monad computation (optional values)
Maybe(Maybe<T>),
/// Either monad computation (error handling)
Either(Either<Error, T>),
/// IO monad computation
IO(IO<T>),
/// State monad computation
State(State<Rc<Environment>, T>),
/// Reader monad computation
Reader(Reader<Rc<Environment>, T>),
/// Composed monadic computation (monad transformers)
Composed {
/// Inner computation
inner: Box<MonadicComputation<Value>>,
/// Transformation function
transform: MonadicTransformation<T>,
},
}