Skip to content

Instantly share code, notes, and snippets.

View alinpopa's full-sized avatar

Alin Popa alinpopa

View GitHub Profile
@alinpopa
alinpopa / finalTagless.ml
Created August 2, 2018 17:33 — forked from lambdahands/finalTagless.ml
Final Tagless in OCaml
(*
* An OCaml implementation of final tagless, inspired from this article by Oleksandr Manzyuk:
* https://oleksandrmanzyuk.wordpress.com/2014/06/18/from-object-algebras-to-finally-tagless-interpreters-2/
*)
module FinalTagless = struct
type eval = { eval : int }
type view = { view : string }
module type ExpT = sig
@alinpopa
alinpopa / gist:e2ea5ee2cdd1299488335135007761e1
Created July 24, 2018 06:53 — forked from relrod/gist:dd748c9ee0b111c3bd47
Pure IO in OCaml via the Free monad
(* Purely functional I/O in Ocaml via the Free monad.
* by Ricky Elrod <relrod@haskell.org>.
*
* This is free and unencumbered software released into the public domain.
*
* Anyone is free to copy, modify, publish, use, compile, sell, or
* distribute this software, either in source code form or as a compiled
* binary, for any purpose, commercial or non-commercial, and by any
* means.
*
@alinpopa
alinpopa / reasonml_gadts.re
Created June 25, 2018 19:40
OCaml GADTs to ReasonML
/* ReasonML equivalent to OCaml's GADTs:
type 'a t =
| Array : 'a array -> 'a t
| Bytes : bytes -> char t
let length (type el) (t:el t) = match t with
| Bytes b -> Bytes.length b
| Array a -> Array.length a
*/
@alinpopa
alinpopa / bitset.go
Created January 20, 2018 09:41 — forked from gabriel-tincu/bitset.go
bitset
package bitset
import "fmt"
const (
chunkSize uint = 8
allSet uint64 = 1<<8 - 1
allReset uint64 = 0
)
(*
*Compile with:
*ocamlfind ocamlc -o test_async -thread -linkpkg -package core,async test_async.ml
*Run with:
*./test_async
*)
open Async.Std
open Core.Std
open Async.Std.Deferred.Infix
(*
*Compile with:
*ocamlfind ocamlc -o test_lwt -thread -linkpkg -package core,lwt,lwt.unix test_lwt.ml
*Run with:
*./test_lwt
*)
open Lwt.Infix
open Core.Std
let rec read_data ic =
type 'a tree =
| Leaf of 'a
| Node of 'a * 'a tree * 'a tree;;
let t = Node (6, (Node (7, (Leaf 1), (Leaf 2))), (Node (8, (Leaf 3), (Leaf 4))));;
let rec parse t =
let rec parse_trees trees acc = match trees with
| [] -> acc
| (Leaf i) :: tl -> parse_trees tl (i + acc)
#require "ppx_sexp_conv";;
let l = [(1, "one"); (2, "two")];;
List.iter l ~f:(fun x ->
[%sexp_of: int * string] x
|> Sexp.to_string
|> print_endline);;
@alinpopa
alinpopa / {680DFBF7-C92D-484D-84BE-06DC3DECCD68}
Created June 29, 2013 12:34
{680DFBF7-C92D-484D-84BE-06DC3DECCD68}
aaaa
package org.test.uml
case class Object(name: String) {
def --(message: String) = (this, message)
def <--(message: String) = (this, message)
}
sealed trait Action
sealed case class Call(source: Object, verb: String, destination: Object) extends Action
sealed case class Async(source: Object, verb: String, destination: Object) extends Action