Skip to content

Instantly share code, notes, and snippets.

@ploki
ploki / Identity_monad.rs
Last active May 24, 2025 16:06
Identity Monad in rust
/// The Identity Monad.
/// the one that shoves in!
//ploki@blackmilk.fr
use std::ops::Shr;
// The Monad trait introduces the monadic bind
trait Monad<A, F> {
type Output;
fn then(self, f: F) -> Self::Output;
}
@ploki
ploki / json_parser_monad.rs
Last active May 6, 2025 05:32
Parser Monad Combinators in rust for a json parser
/// Parser Monad Combinators
/// https://www.cs.nott.ac.uk/~pszgmh/monparsing.pdf
//ploki@blackmilk.fr
use std::env;
use std::fs;
use std::ops::{Add, Deref, Shr};
use std::sync::Arc;
#[derive(Clone)]
struct Interpretation<'a, A>(A, &'a str);
@ploki
ploki / probability_monad.rs
Created August 23, 2024 22:30
Probability distribution monad with rust
//ploki@blackmilk.fr
use std::collections::HashMap;
use std::hash::Hash;
use std::fmt::Debug;
use std::ops::{BitOr,Shr,Mul,Add};
#[derive(Debug, Clone, PartialEq)]
struct Dist<A>
where
A: Eq + Hash + Clone + Debug,