On this page:
Introduction
Part 1:   Join Lists
Part 2:   Lambda Calculus
Part 3:   Unit Testing
What to Turn In
Academic Integrity
6.1.1.7

Project 1: OCaml Warmup

Due: Tues, Feb 17, 2015 11:59:59pm

Introduction

This project will help refresh your memory on programming in OCaml by asking you to write two small modules and then develop test cases for them. You may find it helpful to review the OCaml slides from CMSC 330.

Part 1: Join Lists

Your first task is to implement directed graphs (henceforth just “graphs”) in OCaml. A graph is a collection of nodes and directed edges. In this particular graph implementation, nodes are labeled with some value, and every node and edge may only appear at most once in the graph. For example, a string graph could have nodes labeled "x", "y", and "happy", and there could be edges from "x" to "happy", from "happy" to "x", etc.

It is up to you to decide how to implement graphs. Whatever implementation strategy you use, your graphs must appear to be functional, which means adding and removing nodes and edges does not change a graph, but rather creates a new graph with the added/removed node/edge.

Your graphs should implement the following signature:

type 'a graph

 

val empty : 'a graph

val is_empty : 'a graph -> bool

val insert : 'a graph -> 'a -> 'a graph

val delete : 'a graph -> 'a -> 'a graph

val contains : 'a graph -> 'a -> bool

val nodes : 'a graph -> 'a list

val insert_e : 'a graph -> 'a -> 'a -> 'a graph

val delete_e : 'a graph -> 'a -> 'a -> 'a graph

val contains_e : 'a graph -> 'a -> 'a -> bool

val edges : 'a graph -> ('a * 'a) list

val pred : 'a graph -> 'a -> 'a list

val succ : 'a graph -> 'a -> 'a list

val map : ('a -> 'b) -> 'a graph -> 'b graph

val filter : ('a -> bool) -> 'a graph -> 'a graph

val is_list : 'a graph -> bool

val is_binary_tree : 'a graph -> bool

val path : 'a graph -> 'a -> 'a -> bool

You’ll find the types above in the interface file graph.mli, and you should put your implementation in graph.ml. You can find more detailed descriptions of the above functions in the .ml file, though probably you can guess how these should behave from your knowledge of graphs.

Part 2: Lambda Calculus

Your next task is to implement a few functions related to Lambda calculus, which you learned about in CMSC 330. Below is an interface file lambda.mli. You must implement the last six of the listed functions in lambda.ml. (We’ve already implemented unparse for you.)

type expr =

| Var of string

| Lam of string * expr

| App of expr * expr

 

val unparse : expr -> string

 

val free_vars : expr -> string list

val subst : string -> expr -> expr -> expr

val beta : expr -> expr option

val normal_form : expr -> expr

val expr_of_int : int -> expr

val add : expr -> expr -> expr

These functions should do the following:

Part 3: Unit Testing

Your last task is to write unit tests for parts 1 and 2 above, using OUnit. Put your test cases in the file test.ml, and be sure to add your test cases to the suites suite_graph and suite_lambda, as appropriate. We will grade this part of the project by running your test cases against various correct and incorrect implementations. A test case will only be counted as correct if it passes a correct implementation and fails at least one incorrect implementation.

What to Turn In

Put all your code in the code skeleton we have supplied, and upload your solution to the submit server. You can either upload your solution via the web interface, or you can run java -jar submit.jar in the project directory.

Important note: Follow the instructions from the OCaml lecture notes to get OCaml working on linuxlab (We will not be using linuxlab; I will report what to do instead in class). Please post any questions you have about this on Piazza. You are welcome to install OCaml on your own machine, though we can’t provide much support for that. We do recommend using opam to manage the installation process if you choose to do that.

Academic Integrity

The Campus Senate has adopted a policy asking students to include the following statement on each assignment in every course: “I pledge on my honor that I have not given or received any unauthorized assistance on this assignment.” Consequently your program is requested to contain this pledge in a comment near the top.

Please carefully read the Academic Integrity section of the course syllabus. Any evidence of impermissible cooperation on projects, use of disallowed materials or resources, or unauthorized use of computer accounts, will be submitted to the Student Honor Council, which could result in an XF for the course, or suspension or expulsion from the University. Be sure you understand what you are and what you are not permitted to do in regards to academic integrity when it comes to project assignments. These policies apply to all students, and the Student Honor Council does not consider lack of knowledge of the policies to be a defense for violating them. Full information is found in the course syllabus—please review it at this time.

 

Web Accessibility