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
signature FUNCTOR = sig | |
type 'a F | |
val fmap : ('a -> 'b) -> 'a F -> 'b F (* F is a category theory functor *) | |
end | |
signature FUNCTOR_FIX = sig | |
include FUNCTOR | |
type fix (* The Fixpoint type *) | |
val prj : fix -> fix F (* Recursive *) |
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
trait Rec : Sized{ | |
type F<T>; | |
fn fmap<A,B>(f : impl Fn(A)->B, x : Self::F<A>) -> Self::F<B>; | |
fn prj(t : Self)->Self::F<Self>; | |
fn inj(t : Self::F<Self>)->Self; | |
} | |
fn fold<R : Rec, A>(step : &impl Fn(R::F<A>)->A, x : R )->A { |
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
fn flatten1(t: BinaryTree) -> Vec<i32> { | |
match t { | |
BinaryTree::Leaf(leaf) => Vec::from([leaf]), /* ret */ | |
BinaryTree::Branch((l, r)) => { | |
let mut left /* ret */ = flatten1(*l); //<- rec remember!(r) | |
let right/* ret */ = flatten1(*r); //<- rec remember!(left) | |
left.extend(right); |
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::marker::PhantomData; | |
pub fn main() { | |
let mut s = Splitter::new(); | |
s.list[0] = 1; | |
s.id = 5; | |
println!("Splitter {{list : [{},{}], id : {} }}", s.list[0], s.list[1], s.id); |
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
(* https://www.cs.cmu.edu/~tom7/papers/wang-murphy-recursion.pdf *) | |
signature TYP = sig | |
type t | |
type 'a F | |
val Fmap : ('a -> 'b) -> 'a F -> 'b F | |
val inj : t F -> t | |
val prj : t -> t F | |
end |
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
#![no_implicit_prelude] | |
#![allow(redundant_semicolons)] | |
extern crate core; | |
extern crate alloc; | |
use | |
{ core:: | |
{ option::Option::{*, self} | |
, result::Result::{*, 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
// struct FixSexpr(Sexpr<alloc::boxed::Box<FixSexpr>>); | |
enum SExpr<A=()> { | |
Ground(Arc<str>), | |
Var(i64), | |
App(App<A>) | |
} | |
struct App<A> { f : A, a : A} | |
trait Functor { | |
type F<T>; |
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
datatype 'a Tree = | |
Leaf | |
| Branch of {value : 'a, left : 'a Tree, right : 'a Tree} | |
fun infix_flatten t = case t of | |
Leaf => [] | |
| Branch {value, left, right} => let | |
val l = infix_flatten left | |
val r = infix_flatten right | |
in |
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
Table 2. Average age of mother at first birth: United States and each state, 2006 | |
[By place of residence] | |
All races and | |
origins | |
Non-Hispanic | |
white | |
Non-Hispanic | |
black |
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::{process::Output, usize}; | |
use crate::st::Process; | |
fn main() { | |
type T = Tree; | |
let tree = T::branch( | |
T::branch(T::Leaf, 1, T::Leaf), | |
2, | |
T::branch(T::branch(T::Leaf, 3, Tree::Leaf), 4, Tree::Leaf), | |
); |