FP: Assignment 1 (Oct. 1)

Ken Wakita

13:20-15:50 at W831


Assignment

Published date
Oct. 1, 2018
Due date
Oct. 10, 2018
Method of Submission

OCW-i

Upload answer1.ml at the respective page of OCW-i.

You need to register for this class to open the OCW-i assignment page.

Delayed Submission
Each submission is weighed according to half-value period of 10 days. That means if you submit a perfect answer 30 days after the due date, you will receive \(1/8\) the full points. In other words, you lose \(1 - 1/2^{1/10} \approx 6.7\text {%}\) points each day after the due date has passed. It is very wise to keep the due date.1

READ the MANUAL FIRST

Read the OCaml Manual Chapter1 first. When you are finished, try to answer the following questions.

Your Mission

Download answer1.ml. This is a template file for your answers. You may find half-solved answers to the five problems described below. OCaml interpreter happily accept this file: (Feed this file to OCaml interpreter with ocaml answer1.ml from the command line and OCaml accepts it without any complaint.) However, answer1.ml contains inappropriate definitions at several places. For example area_of_circle and radius_of_circle always answers zeros which are clearly wrong answers in almost all cases.

Your mission is to correctly modify answer1.ml.


Problem 1. volume_of_cube

Define a function named volume_of_cube that takes a cube’s edge length and gives its volume.

Problem 2. edgelen_of_cube

Define a function named edgelen_of_cube that takes a volume of a cube and gives its edge length.

Hint

Problem 3. volumes_of_cubes

Define a function named volumes_of_cubes that takes a list of cubes’ edge lengths and gives their volumes.

Hints

Problem 4. ack

Define ack that computes Ackermann function as defined in Wikipedia

Problem 5. wc

Define wc that takes a list of words and and a word and counts the number of occurrence of the word in the words. For example,

let words = ["The"; "word"; "count"; "is"; "the"; "number"; "of"; "words"; "in"; "a"; "document"; "or"; "passage"; "of"; "text"];;

wc words "of" => 2
wc words "the" => 1
wc (List.map String.lowercase words) "the" => 2

Back to Top


  1. この半減期はトイチ金融よりも遥かに非情なので気をつけて下さい./ This half-value period is much worse than the interest rate of the meanest loan office; time is money.