Skip to content

ky28059/CS456

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CS 456 — Programming Language

OCaml homeworks for CS 456: Programming Language.

hw1_aexp

AST functions, constant fold, and typeCheck and interp for a simple language with

  • Constants / variables
  • Binary operators (+, -, /, *, <, >, =, &&, ||)
  • If expressions if ... then ... else ...

hw2_imp

typeCheck and interp functions for a simple language with

  • Constants / variables
  • Binary operators (+, -, /, *, <, >, =, &&, ||)
  • If expressions if ... then ... else ...
  • Bind expressions let x = ... in ...
  • Sequencing ...; ...
  • References / deref let x = ref ... in *x
  • Assignment x := ...
  • While loops while ... do ...
  • Print statements

hw3_fun

typeCheck and interp functions for a simple language with

  • Constants / variables
  • Binary operators (+, -, /, *, <, >, =, &&, ||)
  • If expressions if ... then ... else ...
  • Bind expressions let x = ... in ...
  • Function binding let sum (x: int, y: int) -> x + y in ...
  • Recursive function binding letrec fact(n : int) : int -> if (n = 0) then 1 else n * fact(n - 1) in ...
  • Function calls sum(...)

hw4_closure

typeCheck and interp functions (implemented 2 ways: closures / environments, and eager substitution) for a simple language with

  • Constants / variables
  • Binary operators (+, -, /, *, <, >, =, &&, ||)
  • If expressions if ... then ... else ...
  • Bind expressions let x = ... in ...
  • Function expressions fun (x: int, y: int) => ...
  • Recursive function binding letrec fact(n : int) : int -> if (n = 0) then 1 else n * fact(n - 1) in ...
  • Function calls sum(...)

hw5_infer

unify and infer functions implementing a type-inference algorithm for a simple language (same constructs as above):

false                                            (* bool *)
let x = 3 in x + 4                               (* int *)
let f = fun(x) => x in f                         (* X -> X *)
let f = fun(x) => x in f(3)                      (* int *)
let f = fun(x) => x in f(true)                   (* bool *)
let f = fun(x) => x + 3 in f                     (* int -> int *)
let f = fun(x, y, z) => if x then y else z in f  (* (bool, X, X) -> X *)
let x = fun(f, x) => f(x) in x                   (* (X -> Y, X) -> Y *)
let y = 10 in let x = fun(f, z) => f(y) in x     (* (int -> X, Y) -> X *)
...

About

Homeworks for CS 456: Programming Languages

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors