(*
-*)
(* HOMEWORK 3
*)
(*
*)
(* NOTE: This homework has 2 parts: hw3.sml and hw3q2.sml
*)
(* THIS FILE CONTAINS CODE FOR QUESTION 2
*)
(*
-*)
exception Unimplemented
(* Functional Parsers *)
(* Functional programming is able to express many problems in v

Assignment 3
COMP 302 Programming Languages and Paradigms
Francisco Ferreira and Andrew Cave
MCGILL UNIVERSITY: School of Computer Science
Due Date: 2:35pm Feb 18 2013
Your homework is due at the beginning of class on Feb 18, 2013. All code les must be
su

Control.Print.printDepth := 100;
(* Question 2: Associative lists *)
(* Question 2.1 *)
(*Here I wrote a foldr funtion as we saw in class because i was having
difficulty with ListPair.foldr. This is the same function, shown by its
type: my_foldr: ('a * 'b

(* COMP 302 Winter 2013 HOMEWORK 2
Instructors: Francisco Ferreira, Andrew Cave
Due 1st February 2013, at the BEGINNING OF CLASS (2:35pm)
*)
(* Question 1 code for reference *)
infix 3 \/
fun m \/ n = Int.max (m,n)
datatype mobile = Object of int | Wir

Assignment 2
COMP 302 Programming Languages and Paradigms
Francisco Ferreira, Andrew Cave
School of Computer Science
McGill University
Due Date: 1 February 2013
General remarks
Your homework is due at the beginning of class on February 1, 2013. You must s

exception notImplemented
(* -*)
(* QUESTION 1 : Partial Sums
*)
(* -*)
(*
Given a list of integers, compute the partial sums
i.e. the sums of all the prefixes
psum: int list -> int list
*)
fun psum_helper [] n
= []
| psum_helper (x:xs) n = (x + n):(psum_h

(*Q2*)
datatype mobile = Object of int | Wire of mobile * mobile;
(*Q2.1 *)
fun weight (Object a) = a
|weight (Wire(l,r) = weight l + weight r;
(*Q2.2*)
fun balanced (Object a) = true
| balanced (Wire(l,r) =
if weight l = weight r andalso balanced l andal

exception notImplemented
(* -*)
(* QUESTION 1 : Partial Sums *)
(* -*)
(*
Given a list of integers, compute the partial sums
i.e. the sums of all the prefixes
psum: int list -> int list
*)
fun psum L = raise notImplemented
(* Some test cases
- psum