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
.
circle_area
Define a function named circle_area
that takes a circle’s radius and gives its area.
radius_of_circle
Define a function named radius_of_circle
that takes an area of a circle and gives its radius.
circle_areas
Define a function named circle_areas
that takes a list of circles’ radii and gives their areas.
You may reuse the definition of circle_area
.
circle_areas [1.0; 3.0; 5.0]
should give [3.14159265358979312; 28.274333882308138; 78.5398163397448315]
.
You may want to use functions from the List
module. You can equally easily solve this problem without using the List module.
mul_num
Define div_num
that emulates faction over numbers: \(n_1 / n_2\).
add_num
defined in Section 1.4rotate
Define a function named rotate
that takes a point coordinate (\(p\): mutable_point
) and an angle in radian (\(\theta\): float
) and performs rotation on \(p\) by \(\theta\) around the origin.
Back to Top
この半減期はトイチ金融よりも遥かに非情なので気をつけて下さい./ This half-value period is much worse than the interest rate of the meanest loan office; time is money.↩