Repository navigation
Expand file tree
/
Copy pathcoursework2.fsx
More file actions
100 lines (74 loc) · 3.39 KB
/
Copy pathcoursework2.fsx
File metadata and controls
100 lines (74 loc) · 3.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
(*
ITT8060 -- Advanced Programming 2014
Department of Computer Science
Tallinn University of Technology
------------------------------------
Coursework 2: 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.
To submit the coursework you will be asked to do the following:
1. Use the Git repository created for coursework 1 at
http://git.ttu.ee/.
2. Upload your solution to the repository as file coursework2.fsx in
directory coursework2.
3. Create a course user for your repository using the public SSH key
provided at
https://git.ttu.ee/courses/itt8060
and give this user read access to your repository.
4. Submit the repository URL to https://git.ttu.ee/courses/itt8060.
The deadline for completing the above procedure is Friday,
September 26, 2014.
Please note that after submitting the repository URL to the course,
all further homework submissions will require creating a new directory
in the existing repository, adding the appropriate files to it, and
committing and pushing them. 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. Write a function rotate : int * char * float -> float * int * char.
// Include type annotations for all arguments and the return type of
// this function, so that it has exactly the above type. Note that F#
// prints the arguments names as well. This is okay.
// 2. Write a function optionalCode : char option -> int option that
// converts and optional character to an optional integer, which is
// its character code.
// 3. Extend the Schedule type such that it contains an optional latest
// occurrence time for recurring events. For example, a schedule for
// the lectures of our course would use a latest occurrence of
// December 23, 2014 to let the lectures end before Christmas.
// 4. Modify getNextOccurences to work with the new Schedule type.
// 5. Consider the following definition of trees whose inner nodes can
// have two or three children and whose leaves are labelled with
// integers:
//
// type Tree =
// | Leaf of int
// | TwoNode of Tree * Tree
// | ThreeNode of Tree * Tree * Tree
//
// Define the value exampleTree : Tree that represents the following
// tree:
//
// *
// / \
// 2 *
// / | \
// 3 5 7
// 6. Define a function sumTree : Tree -> int that computes the sum of
// all labels in the given tree.
// 7. Define a function productTree : Tree -> int that computes the
// product of all labels in the given tree. If this function
// encounters a label 0, it shall not look at any further labels, but
// return 0 right away.
// ** Bonus questions **
// 8. Define a function mapTree : (int -> int) -> Tree -> Tree that
// applies the given function to every label of the given tree.
// 9. Use mapTree to implement a function negateAll : Tree -> Tree that
// negates all labels of a given tree.