Skip to content

Instantly share code, notes, and snippets.

@keigoi
keigoi / README.md
Last active November 22, 2019 05:39
Scribble parallel loop example

Scribble parallel loop example

@keigoi
keigoi / lens.ts
Last active November 9, 2018 13:43
lens typescript
function id<A>(x:A): A {
return x;
}
abstract class Lens<V1, V2, S1, S2> {
abstract get(s: S1): V1;
abstract put(s: S1, v:V2) : S2
}
@keigoi
keigoi / adder_protocol.ml
Created October 21, 2018 10:47
Channel vector generation from Scribble protocol
(*
module fase16.adder.Adder;
type <ocaml> "int" from "stdlib" as Int;
global protocol Adder(role C, role S)
{
choice at C
{
Add(Int, Int) from C to S;
Res(Int) from S to C;
do Adder(C, S);
@keigoi
keigoi / mpst.ml
Last active August 16, 2018 04:03
module type S = sig
type _ mpst
type _ sess
type (_, _, _, _) lens
type (_, _) label
type (_, _, _, _) dlabel
type ('a, 'b, 'c, 'd, 'e, 'f) role = ('a, 'b, 'c, 'd) lens * ('e, 'f) label
type _ typ
module M : sig
type 'a t
val return : 'a code -> 'a t
val (>>=) : 'a t -> ('a code -> 'b t) -> 'b t
val go : unit t -> unit code
end = struct
type 'a t = ('a -> unit) code -> unit code
let return = fun a k -> .< .~k .~a >.
let (>>=) m f = fun k -> .< .~(m .< fun x -> .~(f .< x >. k) >. ) >.
let go : unit t -> unit code = fun m -> m .< fun () -> () >.
@keigoi
keigoi / metaocamltest.ml
Created March 6, 2018 13:16
metaocaml monad
module M : sig
type 'a t
val return : 'a code -> 'a t
val (>>=) : 'a t -> ('a code -> 'b t) -> 'b t
val go : unit t -> unit code
end = struct
type 'a t = ('a -> unit) code -> unit code
let return = fun a k -> .< .~k .~a >.
let (>>=) m f = fun k -> .< .~(m .< fun x -> .~(f .< x >. k) >. ) >.
let go : unit t -> unit code = fun m -> m .< fun () -> () >.
@keigoi
keigoi / sum.v
Last active February 25, 2018 14:35
Require Import Nat.
Require Import Omega. (* fixme *)
Fixpoint sum (n:nat) : nat :=
match n with
| O => O
| S n => S n + sum n
end.
Lemma sum_double : forall (n:nat), sum n * 2 = n * (n + 1).
(* check the behaviour of Coq's rewrite tactics *)
Parameter T : Type.
Lemma mmm1 : forall (x y:T) (p : x = y),
existT (fun (y':T) => x = y') y p = existT (fun (y':T) => x = y') x (eq_refl x).
Proof.
intros.
rewrite p.
reflexivity.
(* compile with ppx_implicits ab783d180c35 (0.3.1) *)
(* ocamlfind ocamlc -c -package ppx_implicits implicit_polyvar.ml *)
module Read = struct
type 'a t = (string -> 'a, [%imp Readers]) Ppx_implicits.t
let unpack : 'a t -> string -> 'a = fun d -> Ppx_implicits.imp ~d
end
let read ?(_reader:'a Read.t option) = match _reader with Some x -> Read.unpack x | None -> failwith "no instance"