Skip to content

Instantly share code, notes, and snippets.

View kayceesrk's full-sized avatar

KC Sivaramakrishnan kayceesrk

View GitHub Profile
@kayceesrk
kayceesrk / serialize_test.sml
Created April 1, 2015 17:38
MLton serialization example
fun serialize1 () =
let
val v = "ABCD"
val ser_v = MLton.serialize v
val v' = MLton.deserialize ser_v
in
print (v' ^ "\n")
end
datatype List = Nil | Cons of (int * List)
@kayceesrk
kayceesrk / stack-overflow.ml
Created June 3, 2015 15:35
Stack overflow
effect E1 : unit
effect E2 : unit
let foo f =
try f () with effect E1 k -> continue k ()
let bar () =
for i = 0 to 1000000 do
Printf.printf "bar %d\n%!" i;
perform E1
@kayceesrk
kayceesrk / spawn.ml
Created June 9, 2015 21:09
spawn continue
effect Wut : unit
effect Wat : unit
let rec foo n =
Printf.printf "[%d] foo\n%!" @@ Domain.self ();
Unix.sleep 1;
if n == 0 then
(perform Wat; foo 1)
else
(perform Wut; foo 1)
@kayceesrk
kayceesrk / test_deadlock.ml
Created August 18, 2015 10:24
Trigger read fault deadlock.
let r1 : int list ref = ref [1024]
let r2 : int list ref = ref [1024]
let rec foo lr fr = function
| 0 -> foo lr fr 1024
| i ->
let v = Random.int i in
lr := [v];
foo lr fr @@ List.hd(!fr)
@kayceesrk
kayceesrk / ocaml-native.md
Last active March 28, 2023 06:19
OCaml native code notes

Concurrency primitives

Signature

(* raw continuation *)
type ('a,'b) stack
perform  : 'a eff -> 'a
resume   : ('a,'b) stack -> ('c -> 'a) -> 'c -> 'b
delegate : 'a eff -> ('a,'b) stack -> 'b
@kayceesrk
kayceesrk / rand.rkt
Created January 19, 2016 13:01
Redex amb
#lang racket
(require redex)
(define-language L
(e (e e)
(λ (x t) e)
x
(amb e ...)
number
(+ e ...)
module type Arrow =
sig
type ('a,'b) t
val arr : ('a -> 'b) -> ('a, 'b) t
val (>>>) : ('a,'b) t -> ('b,'c) t -> ('a,'c) t
val first : ('a,'b) t -> ('a * 'c, 'b * 'c) t
end
module type Arrow_choice =
sig
module type Arrow =
sig
type ('a,'b) t
val arr : ('a -> 'b) -> ('a, 'b) t
val (>>>) : ('a,'b) t -> ('b,'c) t -> ('a,'c) t
val first : ('a,'b) t -> ('a * 'c, 'b * 'c) t
end
module type Arrow_choice =
sig
module type Arrow =
sig
type ('a,'b) t
val arr : ('a -> 'b) -> ('a, 'b) t
val (>>>) : ('a,'b) t -> ('b,'c) t -> ('a,'c) t
val first : ('a,'b) t -> ('a * 'c, 'b * 'c) t
end
module type Arrow_choice =
sig
module type Applicative = sig
type 'a t
val pure : 'a -> 'a t
val (<*>) : ('a -> 'b) t -> 'a t -> 'b t
end
module type Promise = sig
include Applicative
val fork : (unit -> 'a) -> 'a t
val get : 'a t -> ('a, exn) result