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
| // 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
| 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
| 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
| 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
| 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
| 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
| //! 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
| // 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}, |
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 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(); |