Skip to content

Instantly share code, notes, and snippets.

View NicolasT's full-sized avatar

Nicolas Trangez NicolasT

View GitHub Profile
{-# LANGUAGE KindSignatures, DataKinds, RankNTypes,
TypeOperators, TypeFamilies, ScopedTypeVariables, GADTs,
StandaloneDeriving #-}
module Fin where
import Data.Proxy
import Data.Singletons.Prelude
import Data.Singletons.TypeLits
newtype Fin (n :: Nat) = Fin Int
@NicolasT
NicolasT / overflow_lwt.ml
Created May 22, 2014 15:19
OCaml/Lwt core-dump
open Lwt
let go handle =
let rec loop () =
Lwt.catch
loop
handle
in
loop ()
@NicolasT
NicolasT / Main.hs
Created June 11, 2014 13:04
Using Haxl to turn Arakoon `get`s into `multiGetOption` automagically
{-# OPTIONS_GHC -fno-warn-orphans #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE DeriveDataTypeable #-}
{-# LANGUAGE StandaloneDeriving #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE DeriveFunctor #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE DeriveDataTypeable #-}
module Main where
import Prelude hiding (repeat)
@NicolasT
NicolasT / .gitconfig
Created June 20, 2014 13:23
My Git config
[user]
name = $FULL_NAME
email = $EMAIL_ADDRESS
[color]
ui = auto
diff = auto
status = auto
branch = auto
let struct_to_string m =
let parts = List.map (fun (k, v) -> Printf.sprintf "%s = %s" k v) m in
let combined = String.concat "; " parts in
Printf.sprintf "{ %s }" combined
let string_of_string s = Printf.sprintf "%S" s
let string_of_option f = function
| None -> "None"
| Some v -> "Some " ^ f v
@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
@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
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
module Main (insert, delete, lookup, runTrackedMap, main) where
import Prelude hiding (lookup)
import Control.Applicative (Applicative)
import Data.Set (Set)
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