-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Wolfgang Jeltsch
committed
Oct 22, 2014
1 parent
24d2cfc
commit efb6861
Showing
1 changed file
with
75 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
(* | ||
ITT8060 -- Advanced Programming 2014 | ||
Department of Computer Science | ||
Tallinn University of Technology | ||
------------------------------------------------ | ||
Coursework 6: Ensuring data properties via types | ||
------------------------------------------------ | ||
Name: | ||
Student ID: | ||
------------------------------------------------ | ||
Answer the questions below. You answers to the questions should be correct F# | ||
code written after the question. This file is an F# script file; it should be | ||
possible to load the whole file at once. If you can't, then you have | ||
introduced a syntax error somewhere. | ||
This coursework will be graded. | ||
Commit and push your solution to the repository as file coursework6.fsx in | ||
directory coursework6. | ||
The deadline for completing the above procedure is Friday, October 31, 2014. | ||
We will consider the submission to be the latest version of the appropriate | ||
files in the appropriate directory before the deadline of a particular | ||
coursework. | ||
*) | ||
|
||
(* | ||
1. Take the following small module for arbitrary binary trees and extend it | ||
with a function mirror : Tree<'lab> -> Tree<'lab> that takes a binary tree | ||
and mirrors it along the vertical axis. | ||
*) | ||
|
||
module BinaryTree = | ||
|
||
type Tree<'lab> = | ||
| Leaf of 'lab | ||
| Branch of Tree<'lab> * Tree<'lab> | ||
|
||
(* | ||
2. Take the following small module for perfect binary trees and extend it with | ||
the following: | ||
a) a function mirror : Tree<'lab> -> Tree<'lab> that takes a perfect | ||
binary tree and mirrors it along the vertical axis | ||
b) a function toBinary : Tree<'lab> -> BinaryTree.Tree<'lab> that takes a | ||
perfect binary tree and converts it into an ordinary binary tree as | ||
defined in the lecture | ||
*) | ||
|
||
module PerfectBinaryTree = | ||
|
||
type Tree<'lab> = | ||
| Simple of 'lab | ||
| Complex of Tree<'lab * 'lab> | ||
|
||
(* | ||
3. Implement a module PerfectBinaryTernaryTree that contains the following: | ||
a) a type Tree that works like the above type for perfect binary trees, | ||
except that a node may have two or three children | ||
b) a function leaves : Tree<'lab> -> list<'lab> that computes the list of | ||
leaves of a given tree | ||
c) a function mirror : Tree<'lab> -> Tree<'lab> that mirrors a given tree | ||
along the vertical axis | ||
*) |