Skip to content

Instantly share code, notes, and snippets.

View faiface's full-sized avatar

Michal Štrba faiface

View GitHub Profile
type Nat = recursive either {
.zero!
.succ self
}
type List<T> = recursive either {
.empty!
.item(T) self
}
type Nat = recursive either { .zero!, .add1 self }
def drop: [Nat] ! = [n] n begin {
.zero! => !
.add1 n => n loop
}
type Move = either {
.rock!
.paper!
@faiface
faiface / .par
Created February 22, 2025 19:46
Code written during 'Par Hangount - Starting from familiar concepts'
declare unit: !
define unit = !
type Bool = either {
.true !
.false !
}
type Color = either {
.red!
@faiface
faiface / .rs
Last active December 18, 2023 18:43
pub trait Proc: 'static {
type Then<P: Proc>: Proc;
type Dual: Proc;
fn extend(this: Self) -> Self::Then<Noop>;
fn map<P: Proc, Q: Proc>(this: Self::Then<P>, f: impl 'static + FnOnce(P) -> Q) -> Self::Then<Q>;
fn apply<P: Proc>(src: Self::Dual, dst: Self::Then<P>) -> P;
fn then_assc<P: Proc, Q: Proc>(this: Self::Then<P::Then<Q>>) -> <Self::Then<P> as Proc>::Then<Q>;
fn dual_dist<P: Proc>(this: <Self::Dual as Proc>::Then<P::Dual>) -> <Self::Then<P> as Proc>::Dual;
@faiface
faiface / .rs
Created December 11, 2022 14:56
use std::collections::HashMap;
#[derive(Default, Debug)]
struct Dir {
name_and_parent: Option<(String, Box<Dir>)>,
files: HashMap<String, usize>,
subdirs: HashMap<String, Box<Dir>>,
total_size: usize,
}
@faiface
faiface / gist:4b58c78a6903d873a8904e8b861a6bde
Created May 16, 2022 20:07
Snake in Dynamic Modal Playground
(events Left Right Up Down Tick)
(define interpolate
(lambda (dynamic)
(begin [^] (value (@ dynamic))
(or
(after [Tick] (@ dynamic))
(after [^] value)))))
(define direction
@faiface
faiface / .rs
Last active April 20, 2022 23:49
// I have to create a custom type because the undesired behavior
// only occurs if I use a custom type for the parsing result. If
// I tried with something like bool, I get my custom error returned
// back just as I want it. Very strange.
pub enum MyUnit { Only }
// Now this parser returns "found end of input" if the input is not
// equal to "only". But a custom error is generated and wanted to be
// returned instead.
pub fn example() -> impl Parser<char, MyUnit, Error = Simple<char>> {
use std::collections::{BTreeMap, BTreeSet};
#[derive(Debug, Clone)]
struct DFA<State, Action> {
initial: State,
accepting: BTreeSet<State>,
transition: BTreeMap<State, BTreeMap<Action, State>>,
}
@faiface
faiface / .rs
Created February 28, 2022 20:20
use std::collections::{BTreeMap, BTreeSet};
#[derive(Debug)]
struct DFA<State, Action> {
initial: State,
accepting: BTreeSet<State>,
transition: BTreeMap<State, BTreeMap<Action, State>>,
}
from fractions import Fraction
from copy import deepcopy
def places():
for r in range(1, 8+1):
for c in range(1, 8+1):
yield (r, c)
def neighbors(b1, b2):
r1, c1 = b1