This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module CBV where | |
import Prelude hiding (lookup) | |
import qualified Data.Map as Map | |
type Id = String | |
data Exp | |
= Id Id | |
| Fun Id Exp |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Main where | |
import qualified Data.Map as Map | |
type Id = String | |
data Typ | |
= TInt | |
| TFun Typ Typ | |
deriving (Eq) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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 { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) -> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
open Core.Std | |
open Async.Std | |
open OpenFlow0x01 | |
module OFMessage = struct | |
type t = (xid * Message.t) sexp_opaque with sexp | |
end | |
module OpenFlowArg = struct |
OlderNewer