lambdust 0.1.1

A Scheme dialect with gradual typing and effect systems
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
//! Advanced Monad and Applicative Algebra for Lambdust.
//!
//! This module extends the basic monad system with advanced monadic constructs
//! needed for R7RS-large compliance and sophisticated effect handling:
//! - Monad transformers (MonadT)
//! - Maybe, Either, List, IO, State, Reader, Writer monads
//! - Applicative functors and their laws
//! - do-notation syntax sugar support
//! - Free monads and extensible effects

#![allow(missing_docs)]

use super::MonadicValue;
use crate::diagnostics::Result;
use crate::eval::value::Value;
use std::fmt;
use std::marker::PhantomData;
use std::sync::Arc;

/// Simplified trait for monadic computations (without HKT).
/// This avoids Rust's higher-kinded type limitations.
pub trait MonadicOps<A> {
    /// The concrete monadic type
    type Output<B>;
    
    /// Monadic return operation.
    fn pure(value: A) -> Self;
    
    /// Monadic bind operation.
    fn bind<B, F>(self, f: F) -> Self::Output<B>
    where
        F: Fn(A) -> Self::Output<B>;
    
    /// Map a function over the monadic value.
    fn map<B, F>(self, f: F) -> Self::Output<B>
    where
        F: Fn(A) -> B;
}

/// Maybe monad for optional values.
#[derive(Debug, Clone, PartialEq)]
pub enum Maybe<A> {
    Nothing,
    Just(A),
}

/// Either monad for error handling.
#[derive(Debug, Clone, PartialEq)]
pub enum Either<L, R> {
    Left(L),
    Right(R),
}

/// List monad for non-deterministic computations.
#[derive(Debug, Clone, PartialEq)]
pub struct List<A> {
    items: Vec<A>,
}

/// IO monad for side effects.
#[derive(Clone)]
pub struct IO<A> {
    action: Arc<dyn Fn() -> Result<A> + Send + Sync>,
}

impl<A> std::fmt::Debug for IO<A> {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        f.debug_struct("IO")
            .field("action", &"<function>")
            .finish()
    }
}

/// State monad for stateful computations.
#[derive(Clone)]
pub struct State<S, A> {
    run_state: Arc<dyn Fn(S) -> Result<(A, S)> + Send + Sync>,
}

impl<S, A> std::fmt::Debug for State<S, A> {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        f.debug_struct("State")
            .field("run_state", &"<function>")
            .finish()
    }
}

/// Reader monad for environment access.
#[derive(Clone)]
pub struct Reader<R, A> {
    run_reader: Arc<dyn Fn(R) -> Result<A> + Send + Sync>,
}

impl<R, A> std::fmt::Debug for Reader<R, A> {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        f.debug_struct("Reader")
            .field("run_reader", &"<function>")
            .finish()
    }
}

/// Writer monad for accumulating output.
#[derive(Clone)]
pub struct Writer<W, A> {
    run_writer: Arc<dyn Fn() -> Result<(A, W)> + Send + Sync>,
}

impl<W, A> std::fmt::Debug for Writer<W, A> {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        f.debug_struct("Writer")
            .field("run_writer", &"<function>")
            .finish()
    }
}

/// Monad transformer trait (simplified).
pub trait MonadTrans<M> {
    type T<A>;
    
    /// Lift a computation from the base monad.
    fn lift<A>(ma: M) -> Self::T<A>;
}

/// Maybe transformer.
#[derive(Debug, Clone)]
pub struct MaybeT<M, A> {
    run_maybe_t: M, // M<Maybe<A>>
    phantom: PhantomData<A>,
}

/// Either transformer.
#[derive(Debug, Clone)]
pub struct EitherT<E, M, A> {
    run_either_t: M, // M<Either<E, A>>
    phantom: PhantomData<(E, A)>,
}

/// State transformer.
#[derive(Clone)]
pub struct StateT<S, M, A> {
    run_state_t: Arc<dyn Fn(S) -> M + Send + Sync>, // S -> M<(A, S)>
    phantom: PhantomData<A>,
}

impl<S, M, A> std::fmt::Debug for StateT<S, M, A> {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        f.debug_struct("StateT")
            .field("run_state_t", &"<function>")
            .field("phantom", &self.phantom)
            .finish()
    }
}

/// Reader transformer.
#[derive(Clone)]
pub struct ReaderT<R, M, A> {
    run_reader_t: Arc<dyn Fn(R) -> M + Send + Sync>, // R -> M<A>
    phantom: PhantomData<A>,
}

impl<R, M, A> std::fmt::Debug for ReaderT<R, M, A> {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        f.debug_struct("ReaderT")
            .field("run_reader_t", &"<function>")
            .field("phantom", &self.phantom)
            .finish()
    }
}

/// Writer transformer.
#[derive(Debug, Clone)]
pub struct WriterT<W, M, A> {
    run_writer_t: M, // M<(A, W)>
    phantom: PhantomData<(W, A)>,
}

/// Free monad for extensible effects.
#[derive(Debug, Clone)]
pub enum Free<F, A> {
    Pure(A),
    Free(F), // F<Free<F, A>>
}

/// do-notation support structure.
#[derive(Debug, Clone)]
pub struct DoNotation {
    /// Sequence of monadic bindings
    bindings: Vec<DoBinding>,
    /// Final expression
    result: String, // Simplified: store as string
}

/// A single binding in do-notation.
#[derive(Debug, Clone)]
pub struct DoBinding {
    /// Variable name (if any)
    var: Option<String>,
    /// Monadic expression
    expr: String, // Simplified: store as string
}

/// Advanced monad operations.
pub struct MonadOps;

impl<A> Maybe<A> {
    /// Creates a Just value.
    pub fn just(value: A) -> Self {
        Maybe::Just(value)
    }
    
    /// Creates a Nothing value.
    pub fn nothing() -> Self {
        Maybe::Nothing
    }
    
    /// Checks if this is Nothing.
    pub fn is_nothing(&self) -> bool {
        matches!(self, Maybe::Nothing)
    }
    
    /// Checks if this is Just.
    pub fn is_just(&self) -> bool {
        matches!(self, Maybe::Just(_))
    }
    
    /// Converts to Option.
    pub fn to_option(self) -> Option<A> {
        match self {
            Maybe::Just(a) => Some(a),
            Maybe::Nothing => None,
        }
    }
    
    /// Converts from Option.
    pub fn from_option(opt: Option<A>) -> Self {
        match opt {
            Some(a) => Maybe::Just(a),
            None => Maybe::Nothing,
        }
    }
}

impl<L, R> Either<L, R> {
    /// Creates a Left value.
    pub fn left(value: L) -> Self {
        Either::Left(value)
    }
    
    /// Creates a Right value.
    pub fn right(value: R) -> Self {
        Either::Right(value)
    }
    
    /// Checks if this is Left.
    pub fn is_left(&self) -> bool {
        matches!(self, Either::Left(_))
    }
    
    /// Checks if this is Right.
    pub fn is_right(&self) -> bool {
        matches!(self, Either::Right(_))
    }
    
    /// Maps over the Right value.
    pub fn map_right<R2, F>(self, f: F) -> Either<L, R2>
    where
        F: FnOnce(R) -> R2,
    {
        match self {
            Either::Left(l) => Either::Left(l),
            Either::Right(r) => Either::Right(f(r)),
        }
    }
    
    /// Maps over the Left value.
    pub fn map_left<L2, F>(self, f: F) -> Either<L2, R>
    where
        F: FnOnce(L) -> L2,
    {
        match self {
            Either::Left(l) => Either::Left(f(l)),
            Either::Right(r) => Either::Right(r),
        }
    }
}

impl<A> List<A> {
    /// Creates an empty list.
    pub fn empty() -> Self {
        List { items: Vec::new() }
    }
    
    /// Creates a singleton list.
    pub fn singleton(item: A) -> Self {
        List { items: vec![item] }
    }
    
    /// Creates a list from a vector.
    pub fn from_vec(items: Vec<A>) -> Self {
        List { items }
    }
    
    /// Converts to a vector.
    pub fn to_vec(self) -> Vec<A> {
        self.items
    }
    
    /// Checks if the list is empty.
    pub fn is_empty(&self) -> bool {
        self.items.is_empty()
    }
    
    /// Gets the length of the list.
    pub fn len(&self) -> usize {
        self.items.len()
    }
}

impl<A> IO<A> {
    /// Creates a new IO action.
    pub fn new<F>(action: F) -> Self
    where
        F: Fn() -> Result<A> + Send + Sync + 'static,
    {
        IO {
            action: Arc::new(action),
        }
    }
    
    /// Runs the IO action.
    pub fn run(self) -> Result<A> {
        (self.action)()
    }
}

impl<S, A> State<S, A> {
    /// Creates a new state computation.
    pub fn new<F>(f: F) -> Self
    where
        F: Fn(S) -> Result<(A, S)> + Send + Sync + 'static,
    {
        State {
            run_state: Arc::new(f),
        }
    }
    
    /// Runs the state computation.
    pub fn run(self, initial_state: S) -> Result<(A, S)> {
        (self.run_state)(initial_state)
    }
    
    /// Gets the current state.
    pub fn get<St>() -> State<St, St>
    where
        St: Clone + Send + Sync + 'static,
    {
        State::new(|s: St| Ok((s.clone(), s)))
    }
    
    /// Sets the state.
    pub fn put(new_state: S) -> State<S, ()>
    where
        S: Clone + Send + Sync + 'static,
    {
        State::new(move |_| Ok(((), new_state.clone())))
    }
    
    /// Modifies the state.
    pub fn modify<F>(f: F) -> State<S, ()>
    where
        F: Fn(S) -> S + Send + Sync + 'static,
    {
        State::new(move |s| Ok(((), f(s))))
    }
}

impl<R, A> Reader<R, A> {
    /// Creates a new reader computation.
    pub fn new<F>(f: F) -> Self
    where
        F: Fn(R) -> Result<A> + Send + Sync + 'static,
    {
        Reader {
            run_reader: Arc::new(f),
        }
    }
    
    /// Runs the reader computation.
    pub fn run(self, environment: R) -> Result<A> {
        (self.run_reader)(environment)
    }
    
    /// Asks for the environment.
    pub fn ask<Rd>() -> Reader<Rd, Rd>
    where
        Rd: Clone + Send + Sync + 'static,
    {
        Reader::new(|r: Rd| Ok(r.clone()))
    }
    
    /// Asks for a part of the environment.
    pub fn asks<F, B>(f: F) -> Reader<R, B>
    where
        F: Fn(R) -> B + Send + Sync + 'static,
    {
        Reader::new(move |r| Ok(f(r)))
    }
}

impl<W, A> Writer<W, A> {
    /// Creates a new writer computation.
    pub fn new<F>(f: F) -> Self
    where
        F: Fn() -> Result<(A, W)> + Send + Sync + 'static,
    {
        Writer {
            run_writer: Arc::new(f),
        }
    }
    
    /// Runs the writer computation.
    pub fn run(self) -> Result<(A, W)> {
        (self.run_writer)()
    }
    
    /// Writes a value to the log.
    pub fn tell(w: W) -> Writer<W, ()>
    where
        W: Clone + Send + Sync + 'static,
    {
        Writer::new(move || Ok(((), w.clone())))
    }
}

// Simplified monadic instances

impl<A> MonadicOps<A> for Maybe<A> {
    type Output<B> = Maybe<B>;
    
    fn pure(value: A) -> Self {
        Maybe::Just(value)
    }
    
    fn bind<B, F>(self, f: F) -> Self::Output<B>
    where
        F: Fn(A) -> Self::Output<B>,
    {
        match self {
            Maybe::Just(a) => f(a),
            Maybe::Nothing => Maybe::Nothing,
        }
    }
    
    fn map<B, F>(self, f: F) -> Self::Output<B>
    where
        F: Fn(A) -> B,
    {
        match self {
            Maybe::Just(a) => Maybe::Just(f(a)),
            Maybe::Nothing => Maybe::Nothing,
        }
    }
}

impl<L, R> MonadicOps<R> for Either<L, R> {
    type Output<B> = Either<L, B>;
    
    fn pure(value: R) -> Self {
        Either::Right(value)
    }
    
    fn bind<B, F>(self, f: F) -> Self::Output<B>
    where
        F: Fn(R) -> Self::Output<B>,
    {
        match self {
            Either::Right(r) => f(r),
            Either::Left(l) => Either::Left(l),
        }
    }
    
    fn map<B, F>(self, f: F) -> Self::Output<B>
    where
        F: Fn(R) -> B,
    {
        match self {
            Either::Right(r) => Either::Right(f(r)),
            Either::Left(l) => Either::Left(l),
        }
    }
}

impl<A> MonadicOps<A> for List<A> {
    type Output<B> = List<B>;
    
    fn pure(value: A) -> Self {
        List::singleton(value)
    }
    
    fn bind<B, F>(self, f: F) -> Self::Output<B>
    where
        F: Fn(A) -> Self::Output<B>,
    {
        let mut result = Vec::new();
        for item in self.items {
            let mapped = f(item);
            result.extend(mapped.items);
        }
        List::from_vec(result)
    }
    
    fn map<B, F>(self, f: F) -> Self::Output<B>
    where
        F: Fn(A) -> B,
    {
        let mut result = Vec::new();
        for item in self.items {
            result.push(f(item));
        }
        List::from_vec(result)
    }
}

impl MonadOps {
    /// Monadic when - conditional execution for Maybe.
    pub fn when_maybe(condition: bool, action: Maybe<()>) -> Maybe<()> {
        if condition {
            action
        } else {
            Maybe::Just(())
        }
    }
    
    /// Monadic unless - conditional execution (negated) for Maybe.
    pub fn unless_maybe(condition: bool, action: Maybe<()>) -> Maybe<()> {
        Self::when_maybe(!condition, action)
    }
    
    /// Sequence two Maybe computations.
    pub fn sequence_maybe<A, B>(ma: Maybe<A>, mb: Maybe<B>) -> Maybe<(A, B)>
    where
        A: Clone,
        B: Clone,
    {
        ma.bind(|a| mb.clone().map(|b| (a.clone(), b)))
    }
    
    /// Map a function over Maybe values.
    pub fn map_maybe<A, B, F>(f: F, items: Vec<A>) -> Maybe<Vec<B>>
    where
        F: Fn(A) -> Maybe<B>,
    {
        let mut results = Vec::new();
        for item in items {
            match f(item) {
                Maybe::Just(b) => results.push(b),
                Maybe::Nothing => return Maybe::Nothing,
            }
        }
        Maybe::Just(results)
    }
}

impl DoNotation {
    /// Creates a new do-notation block.
    pub fn new() -> Self {
        Self {
            bindings: Vec::new(),
            result: String::new(),
        }
    }
    
    /// Adds a binding to the do-block.
    pub fn bind(mut self, var: Option<String>, expr: String) -> Self {
        self.bindings.push(DoBinding { var, expr });
        self
    }
    
    /// Sets the result expression.
    pub fn result(mut self, expr: String) -> Self {
        self.result = expr;
        self
    }
    
    /// Compiles the do-notation to monadic bind operations.
    pub fn compile(&self) -> String {
        // Simplified compilation
        // A proper implementation would generate proper monadic code
        format!("do {{ {} }}", self.result)
    }
}

// Integration with existing Lambdust effect system

/// Converts a Maybe to a MonadicValue.
pub fn maybe_to_monadic<A>(maybe: Maybe<A>) -> MonadicValue
where
    A: Into<Value>,
{
    match maybe {
        Maybe::Just(a) => MonadicValue::pure(a.into()),
        Maybe::Nothing => MonadicValue::pure(Value::Nil),
    }
}

/// Converts an Either to a MonadicValue.
pub fn either_to_monadic<L, R>(either: Either<L, R>) -> MonadicValue
where
    L: Into<Value>,
    R: Into<Value>,
{
    match either {
        Either::Right(r) => MonadicValue::pure(r.into()),
        Either::Left(l) => MonadicValue::error(super::monad::ErrorAction::Return(l.into())),
    }
}

/// Converts a List to a MonadicValue.
pub fn list_to_monadic<A>(list: List<A>) -> MonadicValue
where
    A: Into<Value>,
{
    let values: Vec<Value> = list.items.into_iter().map(|a| a.into()).collect();
    MonadicValue::pure(Value::list(values))
}

impl fmt::Display for DoNotation {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        writeln!(f, "do")?;
        for binding in &self.bindings {
            if let Some(var) = &binding.var {
                writeln!(f, "  {} <- {}", var, binding.expr)?;
            } else {
                writeln!(f, "  {}", binding.expr)?;
            }
        }
        writeln!(f, "  {}", self.result)
    }
}

impl Default for DoNotation {
    fn default() -> Self {
        Self::new()
    }
}

// Thread safety markers
unsafe impl<A: Send> Send for Maybe<A> {}
unsafe impl<A: Sync> Sync for Maybe<A> {}

unsafe impl<L: Send, R: Send> Send for Either<L, R> {}
unsafe impl<L: Sync, R: Sync> Sync for Either<L, R> {}

unsafe impl<A: Send> Send for List<A> {}
unsafe impl<A: Sync> Sync for List<A> {}

unsafe impl<A: Send> Send for IO<A> {}
unsafe impl<A: Sync> Sync for IO<A> {}

unsafe impl<S: Send, A: Send> Send for State<S, A> {}
unsafe impl<S: Sync, A: Sync> Sync for State<S, A> {}

unsafe impl<R: Send, A: Send> Send for Reader<R, A> {}
unsafe impl<R: Sync, A: Sync> Sync for Reader<R, A> {}

unsafe impl<W: Send, A: Send> Send for Writer<W, A> {}
unsafe impl<W: Sync, A: Sync> Sync for Writer<W, A> {}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn test_maybe_monad_ops() {
        let just_5 = Maybe::just(5);
        let nothing = Maybe::<i32>::nothing();
        
        assert!(just_5.is_just());
        assert!(nothing.is_nothing());
        
        // Test bind
        let result = just_5.bind(|x| Maybe::just(x * 2));
        assert_eq!(result, Maybe::just(10));
        
        let result = nothing.bind(|x| Maybe::just(x * 2));
        assert_eq!(result, Maybe::nothing());
        
        // Test map
        let result = Maybe::just(5).map(|x| x * 2);
        assert_eq!(result, Maybe::just(10));
    }
    
    #[test]
    fn test_either_monad_ops() {
        let right_5 = Either::<String, i32>::right(5);
        let left_err = Either::<String, i32>::left("error".to_string());
        
        assert!(right_5.is_right());
        assert!(left_err.is_left());
        
        // Test bind
        let result = right_5.bind(|x| Either::right(x * 2));
        assert_eq!(result, Either::right(10));
        
        let result = left_err.bind(|x| Either::right(x * 2));
        assert!(result.is_left());
        
        // Test map
        let result = Either::<String, i32>::right(5).map(|x| x * 2);
        assert_eq!(result, Either::right(10));
    }
    
    #[test]
    fn test_list_monad() {
        let list = List::from_vec(vec![1, 2, 3]);
        assert_eq!(list.len(), 3);
        assert!(!list.is_empty());
        
        let empty = List::<i32>::empty();
        assert!(empty.is_empty());
        
        let singleton = List::singleton(42);
        assert_eq!(singleton.len(), 1);
    }
    
    #[test]
    fn test_state_monad() {
        let computation = State::new(|s: i32| Ok((s + 1, s * 2)));
        let result = computation.run(5).unwrap();
        assert_eq!(result, (6, 10));
        
        let get_state = State::<i32, i32>::get();
        let result = get_state.run(42).unwrap();
        assert_eq!(result, (42, 42));
    }
    
    #[test]
    fn test_reader_monad() {
        let reader = Reader::new(|env: String| Ok(env.len()));
        let result = reader.run("hello".to_string()).unwrap();
        assert_eq!(result, 5);
        
        let ask = Reader::<String, String>::ask();
        let result = ask.run("world".to_string()).unwrap();
        assert_eq!(result, "world");
    }
    
    #[test]
    fn test_writer_monad() {
        let writer = Writer::new(|| Ok((42, "logged".to_string())));
        let result = writer.run().unwrap();
        assert_eq!(result, (42, "logged".to_string()));
    }
    
    #[test]
    fn test_do_notation() {
        let do_block = DoNotation::new()
            .bind(Some("x".to_string()), "getValue()".to_string())
            .bind(Some("y".to_string()), "getAnother()".to_string())
            .bind(None, "sideEffect()".to_string())
            .result("return (x + y)".to_string());
        
        assert_eq!(do_block.bindings.len(), 3);
        assert_eq!(do_block.result, "return (x + y)");
    }
}