-
Notifications
You must be signed in to change notification settings - Fork 5
/
coursework3.fsx
74 lines (55 loc) · 2.22 KB
/
coursework3.fsx
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
(*
ITT8060 -- Advanced Programming 2013
Department of Computer Science
Tallinn University of Technology
------------------------------------
Coursework 3: types
------------------------------------
Name:
Student ID:
------------------------------------
Answer the questions below. You answers to 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. Please send the completed coursework
including your name and student ID in the comments by e-mail to
itt8060@cs.ttu.ee by Friday, October 4.
*)
// 1. Write a function rebracket : (int * char) * float -> int * (char * float)
// Include type annotations on all arguments and the
// return type so that it has exactly this type.
// Note: that F# prints the arguments' names as well. This is ok.
// 2. Write a funciton optionfloat : option<int> -> option<float> that
// converts and optional integer to an optional float
//
// 3. extend the Schedule type to support an 'optional' number of
// repeat occurences as an integer.
// 4. modify getNextOccurences to work with the new Schedule type.
// 5. Given this definition of leaf lablelled binary trees:
// type Tree =
// | Node of (Tree * Tree)
// | Leaf of int
//
// Write a function to build a tree from a list. If one reads the
// labels of the tree from left to right then they should be in the
// same order as the original list.
// 6. Write a function to flatten the tree back into a list
// e.g. o Node (Leaf 1,Node (Leaf 2, Leaf 3))
// /\
// 1 o
// / \
// 2 3
//
// [1,2,3]
//
// Note: composing the answers to 5 and 6 should yield the original
// input list (for non-empty lists).
// 7. Create a new tree datatype STree
// where the nodes also carry integers.
// 8. Write a conversion function from Tree to STree
// where you store the sum of the subtrees at the node
// ** bonus question **
// 9. filter out factors of a supplied n from Tree. i.e. remove the factors.
// What happens if you filter out everything?