This file contains hidden or 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
// NOT polymorphism | |
const obj1 = { | |
a: 'a', | |
} | |
const obj2 = { | |
a: 'b' | |
} |
This file contains hidden or 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
fun number_in_months (dates : int*int*int list, months : int list) | |
if null dates | |
then 0 | |
else | |
number_in_month(dates, hd months) + number_in_months(dates, tl months) | |
val test3 = number_in_months ([(2012,2,28),(2013,12,1),(2011,3,31),(2011,4,28)],[2,3,4]) = 3; |
This file contains hidden or 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
fun get_nth (xs : string list, n : int) | |
if null x then 0 | |
else if n = 1 then hd xs | |
else 1 + get_nth (tl xs, n) |
This file contains hidden or 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
fun get_nth (xs : string list, n : int) | |
if n = 1 then hd xs | |
else get_nth (xs, n -1) | |
This file contains hidden or 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
fun date_to_string (date: int*int*int) = | |
let val months = [January, February, March, April, May, June, July, August, September, October, November, December] | |
in | |
get_nth(months, #2 date) ^ " " ^ Int.toString(#3 date) ^ ", " ^ Int.toString(#1 date) | |
end | |
(* errors: *) | |
Error: unbound variable or constructor: December | |
Error: unbound variable or constructor: November |
This file contains hidden or 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
(* Write a function number_before_reaching_sum that takes an int called sum, which you can assume | |
is positive, and an int list, which you can assume contains all positive numbers, and returns an int. | |
You should return an int n such that the first n elements of the list add to less than sum, but the first | |
n + 1 elements of the list add to sum or more. Assume the entire list sums to more than the passed in | |
value; it is okay for an exception to occur if this is not the case. *) | |
fun number_before_reaching_sum (sum : int, xs : int list) = | |
if null xs then 0 | |
else | |
hd xs + number_before_reaching_sum(sum, tl xs) |
This file contains hidden or 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
fun sum_aux (xs, acc, limit) = | |
if acc >= limit then acc | |
else | |
sum_aux (tl xs, acc + hd xs, limit); |
This file contains hidden or 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
(* | |
Write a function number_before_reaching_sum that takes an int called sum, which you can assume | |
is positive, and an int list, which you can assume contains all positive numbers, and returns an int. | |
You should return an int n such that the first n elements of the list add to less than sum, but the first | |
n + 1 elements of the list add to sum or more. Assume the entire list sums to more than the passed in | |
value; it is okay for an exception to occur if this is not the case. | |
*) |
This file contains hidden or 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
(* functions *) | |
fun number_before_reaching_sum (sum : int, xs : int list) = | |
let fun sum_aux (limit, ys, acc, count) = | |
if acc >= limit | |
then count - 1 | |
else | |
sum_aux (limit, tl ys, acc + hd ys, count + 1); | |
in | |
sum_aux(sum, xs, 0, 0) |
This file contains hidden or 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
const express = require('express'); | |
const app = express(); | |
const path = require('path'); | |
app.get('/', (req, res) => { | |
res.sendFile(path.join(__dirname + '/index.html')); | |
}); | |
const port = process.env.PORT || 5656; |