This file contains 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
(* 対称 *) | |
(* float * float -> (float * float) *) | |
let taisho_x p = | |
match p with | |
(x, y) -> (x, -. y) | |
let taisho_x1 = taisho_x (10., 20.) = (10., -20.) | |
let taisho_x2 = taisho_x (8., -5.2) = (8., 5.2) | |
let taisho_x3 = taisho_x (-10.5, 20.1) = (-10.5, -20.1) |
This file contains 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
(* 目的: 中点 *) | |
(* chuten : float * float -> float * float -> float * float *) | |
let chuten p q = | |
match p with | |
(px, py) -> | |
match q with | |
(qx, qy) -> | |
((px +. qx) /. 2., (py +. qy) /. 2.) | |
(* テスト *) |
This file contains 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
(* 目的: 中点 *) | |
(* chuten : float * float -> float * float -> float * float *) | |
let chuten p q = | |
match (p, q) with | |
((px, py), (qx, qy)) -> | |
((px +. qx) /. 2., (py +. qy) /. 2.) | |
(* テスト *) | |
let chuten1 = chuten (1., 1.) (-1., -1.) = (0., 0.) | |
let chuten2 = chuten (-1., 1.) (1., -1.) = (0., 0.) |
This file contains 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
(* 目的: 本に関するレコード型 book_t を宣言する *) | |
type book_t = { | |
title : string; | |
author : string; | |
publisher : string; | |
price : int; | |
isbn : string; | |
} | |
let book1 = { |
This file contains 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
(* 日付 *) | |
type date_t = { | |
year : int; | |
month : int; | |
day : int; | |
} | |
(* 目的: お小遣い帳の情報を格納するレコード型 okozukai_t *) | |
type okozukai_t = { | |
title : string; |
This file contains 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
(* 駅名ひとつ分のデータ ekimei_t *) | |
type ekimei_t = { | |
kanji : string; | |
kana : string; | |
romaji : string; | |
shozoku : string; | |
} | |
(* 目的:駅名をきれいに表示する *) | |
let hyoji e = |
This file contains 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
(* 目的: 受け取ったリストの長さを返す関数length *) | |
(* length : 'a list -> int *) | |
let rec length xs = | |
match xs with | |
[] -> 0 | |
| first :: rest -> 1 + length rest;; | |
(* テスト *) | |
let length1 = length [] = 0;; | |
let length2 = length [1] = 1;; |
This file contains 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
(* 目的: 偶数の要素だけ抽出する *) | |
(* even : int list -> int -> list *) | |
let rec even xs = | |
match xs with | |
[] -> [] | |
| first :: rest -> | |
if first mod 2 = 0 | |
then first :: even rest | |
else even rest;; |
This file contains 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
(* 日付を表現するレコード *) | |
type date_t = { | |
month: int; | |
day: int; | |
} | |
(* 人物を表現するレコード *) | |
type person_t = { | |
height: float; | |
weight: float; |
This file contains 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
(* 日付を表現するレコード *) | |
type date_t = { | |
month: int; | |
day: int; | |
} | |
(* 人物を表現するレコード *) | |
type person_t = { | |
name: string; | |
height: float; |