Skip to content

Instantly share code, notes, and snippets.

View NicolasT's full-sized avatar

Nicolas Trangez NicolasT

View GitHub Profile
{-# LANGUAGE Rank2Types #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE DefaultSignatures #-}
{-# LANGUAGE DeriveDataTypeable #-}
{-# LANGUAGE StandaloneDeriving #-}
{-# LANGUAGE ScopedTypeVariables #-}
module Main where
@NicolasT
NicolasT / either.ml
Created August 25, 2014 14:51
An `Either` module for OCaml
(** Either *)
module Either : sig
type ('a, 'b) t = Left of 'a | Right of 'b
val left : 'a -> ('a, 'b) t
val right : 'b -> ('a, 'b) t
val either : ('a -> 'c) -> ('b -> 'c) -> ('a, 'b) t -> 'c
type x = { xi : int; xv : int }
type y = { yi : int; yv : int }
type var = X of x | Y of y
type equation = { x : int; y : int; c : int }
module VarSet = Set.Make(struct
type t = var
let compare = compare
end)
open Lwt
module Key = struct
type t = string
end
module Value = struct
type t = string
end
import json
id = lambda a: a
flatten_list = lambda f: lambda l: map(f, l)
def flatten_object(l):
sentinel = object()
def f(obj):
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE OverloadedStrings #-}
module Main where
import Control.Monad (unless)
import Data.ByteString (ByteString)
import qualified Data.ByteString as BS (null, splitAt)
import qualified Data.ByteString.Unsafe as BS (unsafeUseAsCString)
module type Monad = sig
type 'a t
val return : 'a -> 'a t
val bind : 'a t -> ('a -> 'b t) -> 'b t
end
module Client : sig
type key = string
type value = string
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
module Main (insert, delete, lookup, runTrackedMap, main) where
import Prelude hiding (lookup)
import Control.Applicative (Applicative)
import Data.Set (Set)
@NicolasT
NicolasT / exh.ml
Last active August 29, 2015 14:03
OCaml exhaustiveness checking in face of GADTs and recursive modules
(* This works *)
module W = struct
type a
type b
type (_, _) t =
| AA : (a, a) t
| AB : (a, b) t
| BB : (b, b) t
@NicolasT
NicolasT / fsm.ml
Last active August 29, 2015 14:03
Using GADT witnesses to restrict FSM state transitions & acceptable events per state
(* Module overview:
*
* Transition : contains a witness of valid transitions
* State : wrapper for states, and handler for events given some state
* Event : incoming events
* Effect : resulting effects
* Follower / Candidate / Leader : states
*
* Every module of Follower, Candidate and Leader have a state type, t, and an
* 'event_witness' type which defines the events their respective handler