This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type Nat = recursive either { | |
.zero! | |
.succ self | |
} | |
type List<T> = recursive either { | |
.empty! | |
.item(T) self | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type Nat = recursive either { .zero!, .add1 self } | |
def drop: [Nat] ! = [n] n begin { | |
.zero! => ! | |
.add1 n => n loop | |
} | |
type Move = either { | |
.rock! | |
.paper! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
declare unit: ! | |
define unit = ! | |
type Bool = either { | |
.true ! | |
.false ! | |
} | |
type Color = either { | |
.red! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(events Left Right Up Down Tick) | |
(define interpolate | |
(lambda (dynamic) | |
(begin [^] (value (@ dynamic)) | |
(or | |
(after [Tick] (@ dynamic)) | |
(after [^] value))))) | |
(define direction |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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>> { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use std::collections::{BTreeMap, BTreeSet}; | |
#[derive(Debug, Clone)] | |
struct DFA<State, Action> { | |
initial: State, | |
accepting: BTreeSet<State>, | |
transition: BTreeMap<State, BTreeMap<Action, State>>, | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use std::collections::{BTreeMap, BTreeSet}; | |
#[derive(Debug)] | |
struct DFA<State, Action> { | |
initial: State, | |
accepting: BTreeSet<State>, | |
transition: BTreeMap<State, BTreeMap<Action, State>>, | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
NewerOlder