Skip to content

Instantly share code, notes, and snippets.

View arjunguha's full-sized avatar
:shipit:
Why does this exist?

Arjun Guha arjunguha

:shipit:
Why does this exist?
View GitHub Profile
@arjunguha
arjunguha / Server.ml
Created December 12, 2013 15:13
Cohttp server example
(* Read this chapter:
https://realworldocaml.org/v1/en/html/concurrent-programming-with-async.html
You'll need to understand some of these interfaces:
- https://github.com/avsm/ocaml-cohttp/tree/master/cohttp
- https://github.com/avsm/ocaml-cohttp/tree/master/async
@arjunguha
arjunguha / Async_OpenFlow0x01_Tcp.ml
Created December 12, 2013 05:05
Typed_tcp for OpenFlow 1.0
open Core.Std
open Async.Std
open OpenFlow0x01
module OFMessage = struct
type t = (xid * Message.t) sexp_opaque with sexp
end
module OpenFlowArg = struct
@arjunguha
arjunguha / AsyncICQ.ml
Created December 11, 2013 19:22
Basic
open Core.Std
open Async.Std
let print_reader (reader : Reader.t) : unit Deferred.t =
Pipe.iter (Reader.lines reader)
(fun (str: string) -> printf "Read from network: %s\n%!" str; return ())
let write_lines (writer : Writer.t) : unit Deferred.t =
Pipe.iter (Reader.lines (Reader.create (Fd.stdin ())))
(fun (str : string) ->
@arjunguha
arjunguha / Main.ml
Created December 11, 2013 14:38
Async In_thread in action.
open Core.Std
open Async.Std
let rec interval_rec acc min max =
if min > max then acc else interval_rec (min :: acc) (succ min) max
let interval min max = List.rev (interval_rec [] min max)
let remove_multiples_of n lst =
List.filter lst (fun m -> m mod n <> 0)
package cs691f.parsers
package attempt0 {
class Parser[A](val parse : String => Option[A]) { self =>
def alt(other : Parser[A]) =
new Parser(str => self.parse(str) match {
case Some(x) => Some(x)
case None => other.parse(str)
@arjunguha
arjunguha / gist:7619254
Last active December 29, 2015 05:08
CEK
type k =
| Top
| AddR of env * exp * k
| AddL of int * k
| AppR of env * exp * k
| AppL of env * id * exp * k
let step (e : exp) (env : env) (k : k) : exp * env * k = match (e, k) with
| Add (e1, e2), _ -> e1, env, AddR (env, e2, k)
| Int n, AddR (env', e2, k') -> e2, env', AddL (n, k')
@arjunguha
arjunguha / ExpressionProblem.scala
Created November 13, 2013 23:53
Script from class
// Based on "Independently Extensible Solutions to the Expression Problem" by
// by Matthias Zenger and Martin Odersky, from FOOL 2005.
//
// http://lampwww.epfl.ch/~odersky/papers/ExpressionProblem.html
//
// I was using Scala 2.10.3
trait Base {
trait Exp {
module Main where
import qualified Data.Map as Map
type Id = String
data Typ
= TInt
| TFun Typ Typ
deriving (Eq)
#lang racket
(require redex)
(require "resugar-redex.rkt")
(require "lang-min.rkt")
(define-macro Cons
[(Cons hd tl) (λ mk-cons (λ mk-empty (apply (apply mk-cons hd) tl)))])
; -1 for a thunk here
@arjunguha
arjunguha / CBV.hs
Created September 29, 2013 01:12
Typical CBV evaluator
module CBV where
import Prelude hiding (lookup)
import qualified Data.Map as Map
type Id = String
data Exp
= Id Id
| Fun Id Exp