Skip to content

Instantly share code, notes, and snippets.

@ClarkeRemy
ClarkeRemy / json.rs
Last active November 7, 2025 06:48
JSON object to indicies format
use std::{fmt::Debug, rc::Rc};
const THE_JSON : &str = r#"{
"first_name": "John",
"last_name": "Smith",
"is_alive": true,
"age": 27,
"address": {
"street_address": "21 2nd Street",
"city": "New York",
@ClarkeRemy
ClarkeRemy / parens.c
Created October 6, 2025 16:02
Simple Sexpr tokenizer
#include <stdio.h>
#include <stdint.h>
#include <stddef.h>
#define false 0
#define true !false
char* input = "(a bc (def \n 5) 7)";
@ClarkeRemy
ClarkeRemy / tagless.rs
Last active October 28, 2025 03:15
Tagless Final simple
#[derive(Debug,Clone)]
enum Expr {
Val(i32),
Neg(Box<Expr>),
Sum(Box<Expr>, Box<Expr>),
Mul(Box<Expr>, Box<Expr>),
Var(String),
}
@ClarkeRemy
ClarkeRemy / main.c
Last active September 17, 2025 08:10
simple linked list in C
#include <stdalign.h>
#include <stdint.h>
#include <stddef.h>
#include <stdio.h>
struct List {
enum { NODE, END } tag;
union {
struct { void* val; struct List* next; } node;
struct { } end;
@ClarkeRemy
ClarkeRemy / sort_permutation.rs
Created July 4, 2025 18:03
Sort Permutation
fn main(){
// let list = ["zabc", "ghjjklhgkj", "kgjgfhfgdg", "zabcd", "hghfgft", "afsbdgshng"];
let mut list = [3,6,2,1];
let mut list_ = [3,6,2,1];
let mut other_list = *b"abcd";
let mut other_list_ = *b"abcd";
let mut perm = Vec::new();
let mut perm_perm = Vec::new();
let mut perm_perm_perm = Vec::new();
// Implements the cool-lex algorithm to generate (n,k)-combinations
// @article{Ruskey:2009fk,
// Author = {Frank Ruskey and Aaron Williams},
// Doi = {10.1016/j.disc.2007.11.048},
// Journal = {Discrete Mathematics},
// Month = {September},
// Number = {17},
// Pages = {5305-5320},
// Title = {The coolest way to generate combinations},
// Url = {http://www.sciencedirect.com/science/article/pii/S0012365X07009570},
@ClarkeRemy
ClarkeRemy / multiplate.rs
Created April 28, 2025 04:22
Multiplate Rust
//! this library is largely "incorrect" in the sense that projectors should be exitentials and not part of type arguments
// https://hackage.haskell.org/package/multiplate-0.0.3/docs/src/Data-Generics-Multiplate.html
use std::{marker::PhantomData};
pub trait Funct {
type F<T>;
}
@ClarkeRemy
ClarkeRemy / rust_variance.rs
Last active April 24, 2025 07:27
rust lifetime variance (fail mains does note compile)
use std::marker::PhantomData;
// CONTRAVARIANT
struct Contra<'contra> (PhantomData<
fn(&'contra ()) -> ()
>);
// succeeds (contravariant "lengthening")
fn contra_1<'a>( contra : Contra<'a>) -> Contra<'static> {
contra
}
@ClarkeRemy
ClarkeRemy / main.ml
Last active April 3, 2025 10:33
Ocaml abstract list
type 'a list= List of { l : 'z . (unit -> 'z) -> ('a * 'a list -> 'z) -> 'z }
let nil : 'a list = List{ l = fun f -> fun _ -> f()}
let cons (v : 'a) (r : 'a list) : 'a list=
List{ l = fun _ -> fun f -> f(v,r) }
let ex : int list = cons 3 (cons 1 (cons 2 nil))
let length (l : 'a list) : int =
@ClarkeRemy
ClarkeRemy / bad_typeclass.prolog
Created April 1, 2025 14:36
Bad Typeclass Prolog
fAtoB_optionA_optionB(_, none, none).
fAtoB_optionA_optionB(F, option(A), option(B)) :- C =.. [F,A,B], C.
functor_map(option, fAtoB_optionA_optionB).
fmapAtoB_fA_fB(Func, F_A, F_B) :-
( nonvar(F_A) -> F_A =.. [F| _]
; nonvar(F_B) -> F_B =.. [F| _]
),
functor_map(F, Map),