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
//! 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>; | |
} |
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; | |
// CONTRAVARIANT | |
struct Contra<'contra> (PhantomData< | |
fn(&'contra ()) -> () | |
>); | |
// succeeds (contravariant "lengthening") | |
fn contra_1<'a>( contra : Contra<'a>) -> Contra<'static> { | |
contra | |
} |
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 '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 = |
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
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), |
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; | |
/// We limit the size of a node to u16::MAX. If you want bigger, make a tree or use a Tensor | |
pub type Mem = u16; | |
pub type Offset = usize; | |
type InternalHandleRepr = u32; | |
struct InternalHandle<T>{handle : InternalHandleRepr, _boo : PhantomData<T>} | |
pub type ExtHandleRepr = u64; |
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 flatten t = case t of | |
Leaf => [] | |
| Branch {value, left, right} => let |
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://docs.rs/rust2fun/latest/src/rust2fun/combinator.rs.html#399-417 | |
trait Rec<T, R> { | |
fn apply(&self, x: T) -> R; | |
} | |
impl<T, R, F> Rec<T, R> for F | |
where | |
F: Fn(&dyn Rec<T, R>, T) -> R, |
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 core::ops::ControlFlow; | |
use std::{marker::PhantomData, sync::Arc}; | |
// HKT | |
#[allow(non_camel_case_types)] | |
pub type a_<'a, F, T> = <F as A_Funct>::F<'a, T>; | |
#[allow(non_camel_case_types)] |
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 expr = PLUS of expr * expr | |
| NUM of int | |
fun eval_expr (NUM n) = n | |
| eval_expr (PLUS (l,r)) = eval_expr l + eval_expr r | |
fun pretty_expr (NUM n) = Int.toString n | |
| pretty_expr (PLUS (l,r)) = "( " ^ pretty_expr l ^ " + " ^ pretty_expr r ^ " )" |
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
fun y f x = f (y f) x | |
functor Fix(type 'a f ) | |
= struct | |
type 'a f = 'a f | |
datatype fix = FIX of fix f | |
fun inj v = FIX v | |
fun prj (FIX v) = v | |
end |
NewerOlder