Skip to content

Instantly share code, notes, and snippets.

@kamenchunathan
kamenchunathan / main.rs
Created February 27, 2024 13:07
Monoid, Functor, Applicative and Monad in Rust
trait Semigroup {
type A;
fn append(_: Self::A, _: Self::A) -> Self::A;
}
trait Monoid {
type A: Semigroup;
fn empty() -> Self::A;
}
@kamenchunathan
kamenchunathan / Cargo.toml
Created November 7, 2023 09:05
Bevy serialization and Reflection
[package]
name = "ping"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
bevy = {version = "0.12",features = ["asset_processor", "basis-universal"]}
@kamenchunathan
kamenchunathan / ast.rs
Created April 2, 2023 15:53
A parser for arithmetic operations in rust
#[derive(Debug)]
pub enum Tree<T, U> {
Leaf(T),
Node(Box<Tree<T, U>>, U, Box<Tree<T, U>>),
}
pub trait Op<T> {
fn apply(&self, x: T, y: T) -> T;
}
@kamenchunathan
kamenchunathan / Cargo.toml
Created March 18, 2023 16:38
An attempt at a lambda calculus parser
[package]
name = "lambda_calculus"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
nom = "7.1.3"
@kamenchunathan
kamenchunathan / Json.purs
Created March 16, 2023 16:07
playing with parser combinators
module Data.Json (Json(..), JsonValue(..)) where
import Prelude
import Data.String (joinWith)
import Data.Tuple (Tuple(..))
data JsonValue
= JsonString String
| JsonNumber Number
@kamenchunathan
kamenchunathan / Playground.hs
Created August 11, 2022 11:34
Plutus Playground Smart Contract
-- A game with two players. Player 1 thinks of a secret word
-- and uses its hash, and the game validator script, to lock
-- some funds (the prize) in a pay-to-script transaction output.
-- Player 2 guesses the word by attempting to spend the transaction
-- output. If the guess is correct, the validator script releases the funds.
-- If it isn't, the funds stay locked.
import Control.Monad (void)
import Data.ByteString.Char8 qualified as C
import Data.Map (Map)
import Data.Map qualified as Map