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 / Arith.ml
Last active December 22, 2015 14:48
Code from Friday, September 6th
open Arith_syntax
let rec subst (x : id) (v : int) (e : exp) : exp =
match e with
| Int _ -> e
| Add (e1, e2) -> Add (subst x v e1, subst x v e2)
| Mul (e1, e2) -> Mul (subst x v e1, subst x v e2)
| Let (y, e1, e2) ->
Let (y, subst x v e1, if x = y then e2 else subst x v e2)
| Id y -> if x = y then Int v else Id y
@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
#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
module Main where
import qualified Data.Map as Map
type Id = String
data Typ
= TInt
| TFun Typ Typ
deriving (Eq)
@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 {
@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')
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 / 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)
@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 / 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