13:20-15:50 at W831
Upload answer1.ml
at the respective page of OCW-i.
You need to register for this class to open the OCW-i assignment page.
Read the OCaml Manual Chapter1 first. When you are finished, try to answer the following questions.
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
.
volume_of_cube
Define a function named volume_of_cube
that takes a cube’s edge length and gives its volume.
edgelen_of_cube
Define a function named edgelen_of_cube
that takes a volume of a cube and gives its edge length.
volumes_of_cubes
Define a function named volumes_of_cubes
that takes a list of cubes’ edge lengths and gives their volumes.
You may reuse the definition of volume_of_cube
.
volumes_of_cubes [1.0; 3.0; 5.0]
should give [1.; 27.; 125.]
.
You may want to use functions from the List
module. You can equally easily solve this problem without using the List module.
ack
Define ack
that computes Ackermann function as defined in Wikipedia
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
この半減期はトイチ金融よりも遥かに非情なので気をつけて下さい./ This half-value period is much worse than the interest rate of the meanest loan office; time is money.↩