\documentclass[12pt]{myjarticle}

\usepackage{fullpage}
\usepackage{url}
\usepackage[dvipdfmx]{color}
\usepackage[dvipdfmx]{graphicx}
\usepackage{alltt}
\usepackage{ascmac}

%\usepackage{amsmath}
%\usepackage{amssymb}
%\usepackage{amsthm}

\newcommand{\returnKey}{\keytop{\return}}
\definecolor{darkgreen}{rgb}{0.0,0.5,0.1}
\definecolor{lightgray}{gray}{0.85}
\definecolor{gray}{gray}{0.45}
\newcommand{\keywords}[1]{{\textcolor{darkgreen}{$B!J%-!<%o!<%I!'(B#1$B!K(B}}}
\newcommand{\code}[1]{$B!V(B{\texttt{#1}}$B!W(B}
\newcommand{\ocaml}{Objective Caml}

%\theoremstyle{definition}
%\newtheorem{exercise}{$BN}=,(B}[section]

\newcommand{\exref}[1]{$BN}=,(B\ref{#1}}

\makeatletter
\newcounter{exercise}[section]
\newenvironment{exercise}%
{
\stepcounter{exercise}%
\def\@currentlabel{\thesection.\theexercise}
\vskip 12pt plus 2.0pt minus 2.0pt%
\noindent%
\textbf{$BN}=,(B\nobreak\thesection.\theexercise{}}
}{%
\vskip 12pt plus 2.0pt minus 2.0pt%
}
\makeatother


\newcommand{\system}[1]{\textcolor{gray}{#1}}

%\setlength{\parskip}{10pt plus 2.0pt minus 2.0pt}


\newenvironment{keypoint}[1]{\begin{itembox}[l]{Key Point: #1}}{\end{itembox}}
\newenvironment{hint}{\noindent{}$B%R%s%H!'(B}{}

\chardef\us=`\_
\chardef\bs=`\\
\chardef\charhat=`\^
\chardef\chartilde=`\~

\newenvironment{note}{\par\noindent\textbf{$BCm0U!'(B}}{}

\newenvironment{myimage}{\begin{quote}}{\end{quote}}

\newenvironment{programcode}{%
% \newbox\codebox%
% \setbox\codebox=\vbox\bgroup%
\parskip0pt
\baselineskip=13pt
\begin{alltt}\leftskip2em%
}{%
\end{alltt}%
% \egroup%
% {\unvbox\codebox}
%\renewcommand{\baselinestretch}{}\selectfont%
}

\setlength{\fboxsep}{2pt}

\let\oldsection=\section
\def\section#1{\oldsection{#1\nobreak\vskip 1pt\nobreak\hrule width \linewidth height 1.5pt\nobreak}%
\vskip .4\Cvs plus .2\Cvs
}

%\title{2010$BG/EYAOB$9)3X8&=$!V(BE48$B@h?J%W%m%0%i%_%s%0BN83!JA0H>!K!W(BObjective Caml$BF~Lg%o!<%/%V%C%/(B}
%\date{}
%\author{}

\begin{document}

\noindent
{\small 2010$BG/EYAOB$9)3X8&=$!V(BE48$B@h?J%W%m%0%i%_%s%0BN83!JA0H>!K!W(B}
\smallskip\\
\scalebox{1.2}{\Huge\bfseries\sffamily Objective Caml$BF~Lg%o!<%/%V%C%/(B}
\smallskip





\setcounter{section}{-1}
\section{$B%W%m%i%_%s%0$C$F2?$@$m$&!)(B}
\keywords{$B%W%m%0%i%`!$%W%m%0%i%_%s%08@8l(B}

\section{\ocaml{}$B$N%$%s%9%H!<%k(B}

\begin{enumerate}
\item WWW$B%V%i%&%6$G!$(B\url{http://caml.inria.fr/}$B$K%"%/%;%9(B
$B!%(B
\begin{myimage}
\resizebox{240pt}{!}{\includegraphics{caml_inria.eps}}
\end{myimage}

\item $B%Z!<%8>eIt!V(BDownload$B!W$N%j%s%/$rC)$j!$!V(BObjective Caml$B!W$N(B
$B!V(BSelf installer (3.11.0) for the port based on the Microsoft toolchain$B!W$N(B
$B!V(BSelf install$B!W%j%s%/$rC)$k$3$H$G!$(B
 \texttt{ocaml-3.11.0-win-msvc.exe}$B$r%@%&%s%m!<%I!%(B

\begin{myimage}
\resizebox{240pt}{!}{\includegraphics{download_selfinstaller.eps}}
\end{myimage}

\item \texttt{ocaml-3.11.0-win-msvc.exe}$B$r<B9T!%(B


\item $B%$%s%9%H!<%i$,5/F0$9$k$N$G!$$"$H$O%$%s%9%H!<%i$N;X<($K=>$&!%(B
$B4pK\E*$K!V$O$$!W!$!V(BNext$B!W!$!V(Binstall$B!W!$!V(Bfinish$B!W$J$I$r%/%j%C%/$9$l$P$h$$!%(B

\begin{myimage}
\resizebox{130pt}{!}{\includegraphics{caml_install_1.eps}}
\resizebox{130pt}{!}{\includegraphics{caml_install_2.eps}}
\resizebox{130pt}{!}{\includegraphics{caml_install_3.eps}}\\
\resizebox{130pt}{!}{\includegraphics{caml_install_4.eps}}
\resizebox{130pt}{!}{\includegraphics{caml_install_5.eps}}
\resizebox{130pt}{!}{\includegraphics{caml_install_6.eps}}\\
\resizebox{130pt}{!}{\includegraphics{caml_install_7.eps}}
\resizebox{130pt}{!}{\includegraphics{caml_install_8.eps}}
\raisebox{4\Cvs}{\parbox{130pt}{$B:G8e$N%A%'%C%/%\%C%/%9$O$O$:$9!%(B}}
\end{myimage}



\end{enumerate}

\section{\ocaml{}$B$N5/F0$H=*N;(B}

\subsection*{\ocaml $B$r5/F0$7$F$_$h$&(B}

\begin{enumerate}
\item $B!V%9%?!<%H!W"*!V$9$Y$F$N%W%m%0%i%`!W"*!V%"%/%;%5%j!W"*!V%3%^%s%I%W%m%s%W%H!W(B
      $B$r%/%j%C%/!%(B

\begin{myimage}
\begin{tabular}[c]{lcl}
 \begin{tabular}{l}\resizebox{150pt}{!}{\includegraphics{start_command_prompt.eps}}\end{tabular}
 & $\longrightarrow$ & 
 \begin{tabular}{l}\resizebox{150pt}{!}{\includegraphics{command_prompt.eps}}
 \end{tabular}
\end{tabular}
\end{myimage}

\item $B=P$F$-$?%&%#%s%I%&$NCf$G(B
\code{ocaml}
$B$HF~NO!J$+$.3g8L$OF~NO$7$J$$!%0J2<F1MM!K$7!$(BEnter$B%-!<$r2!$9!%(B
$B$I$N$h$&$J2hLL$,=PNO$5$l$?$@$m$&$+!)(B
\keywords{$B%P!<%8%g%s!$%W%m%s%W%H(B}



\end{enumerate}

\subsection*{\ocaml $B$r=*N;$7$F$_$h$&(B}

$B%W%m%s%W%H!V(B\system{\texttt{\#}}$B!W$,I=<($5$l$?>uBV$G(B\code{\# quit;;}$B$HBG$C$F(B
Enter$B%-!<$r2!$9!%(B
$B%W%m%s%W%H$N(B\system{\texttt{\#}}$B$H$OJL$K!$$b$&0l$D<+J,$G(B\texttt{\#}$B$rF~NO$9$kI,MW$,$"$k$3$H$KCm0U!%(B

$B@5>o$K=*N;$7$?$i!$0J2<$N$?$a$K$^$?(BObjective Caml$B$r5/F0$7$F$*$3$&!%(B
$B$J$*!$$b$7(BObjective Caml$B$r<B9T$7$F$h$/$o$+$i$J$$>uBV$K$J$C$?$i!$(B
\code{Ctrl$B%-!<$r2!$7$J$,$i(Bc}$B$r2!$;$P%W%m%s%W%H$KLa$k$N$G!$(B
$B4V0c$($?LdBj$+$i$d$j$J$*$;$P$h$$!%$=$l$G$b$*$+$7$+$C$?$i!$(B
Objective Caml$B<+BN$r=*N;$7!$5/F0$7$J$*$7!$>O$N;O$a$NLdBj$+$i$d$j$J$*$9!%(B


\section{$B@0?t1i;;(B}

\begin{exercise}
\code{1 + 2 ;;}$B$HF~NO$7(BEnter$B%-!<$r2!$7$F$_$h$&!%2?$,I=<($5$l$?$+!)(B
\keywords{$B<0!$I>2A!$CM!$7?(B}
\end{exercise}

\begin{exercise}
  \code{3 * 4 ;;}$B$G$O$I$&$+!)(B
\end{exercise}

\begin{exercise}
  \code{1 + 2 * 3 ;;}$B$G$O$I$&$+!)(B\code{(1 + 2) * 3 ;;}$B$O!)(B
\keywords{$BM%@h=g0L(B}
\end{exercise}

\begin{exercise}
$B!V(B\texttt{+}$B!W$d!V(B\texttt{*}$B!W$NB>$K!$@0?t$N0z$-;;$rI=$9!V(B\texttt{-}$B!W$d(B
$B@0?t$N3d$j;;$N>&$rI=$9!V(B\texttt{/}$B!W!$M>$j$rI=$9!V(B\texttt{mod}$B!W$J$I$,;H$($k!%(B
$B$=$l$>$l$NF0:n$r3NG'$7$F$_$h$&!%Ii$N?t$G$O$I$&$+!)(B
$B$?$H$($P!$(B
  \code{3 - 5;;} $B!$(B
  \code{7 mod 3;;}$B!$(B
  \code{7 / 3;;} $B!$(B
  \code{(-1) * 9;;}
$B$J$I$r;n$7$F$_$h$&!%(B
\end{exercise}

$B0lHL$K<0$rI>2A$9$k$K$O!$<0$N8e$K(B\code{;;}$B$r$D$1$F(BEnter$B%-!<$r2!$;$P$h$$!%(B
$B0J2<$G$O!$<0$N8e$N(B\code{;;}$B$r$7$P$7$P>JN,$9$k!%(B

% \begin{keypoint}{$B<0$NI>2A(B}
%  \begin{alltt}$B<0(B;;\end{alltt}
% \end{keypoint}

\section{$B>.?t1i;;(B}

\begin{exercise}
\code{1.2 +. 3.4}$B!$(B\code{1.2 *. 3.4}$B!$(B\code{5.0 +. 6.7}$B$r$=$l$>$l(B
$BI>2A$7$F$_$h$&!%!V(B\texttt{+}$B!W$d!V(B\texttt{*}$B!W$N8e$K$D$$$F$$$k!V(B\texttt{.}$B!W$rK:$l$J$$$3$H!%(B
\end{exercise}

\begin{exercise}
\code{1.2 +. 3.4}$B!J!V(B\texttt{+}$B!W$N8e$K!V(B\texttt{.}$B!W$,$J$$!K$d(B
\code{5 +. 6.7}$B!J(B\texttt{5.0}$B$NBe$o$j$K(B\texttt{5}$B!K$rI>2A$7$h$&$H$9$k$H!$(B
$B$I$&$J$k$@$m$&$+!)(B\keywords{$B7?8!::(B/$B7?%A%'%C%/(B}
\end{exercise}

\begin{exercise}
\code{1.0 /. 3.0}$B$rI>2A$9$k$H$I$&$J$k$+!)(B
\code{1.0 +. 1.0 +. 1.0}$B$O$I$&$+!)(B
\keywords{$BIbF0>.?tE@!$IbF0>.?tE@1i;;(B}
\end{exercise}

\begin{exercise}
\ocaml $B$rMQ$$$F!$H>7B(B 1.23 $B$N1_$NLL@Q$H<~$ND9$5$r5a$a$F$_$h$&!%(B
$B$?$@$7!$1_<~N($O(B3.14159265359$B$H$9$k!%(B
\begin{hint}
$BH>7B(B$r$$B$N1_$NLL@Q$O(B$\pi r^2$$B!$<~$ND9$5$O(B$2 \pi r$$B!%(B
\end{hint}
\end{exercise}

\section{$BJQ?t$NDj5A$H;HMQ(B}

\begin{exercise}
\ocaml $B$rMQ$$$F!$H>7B(B 4.5 $B$N1_$NLL@Q$H<~$ND9$5$r5a$a$F$_$h$&!%(B
$BH>7B(B 67.89 $B$N1_$G$O$I$&$+!)(B
\label{ex:def_pi_try}
\end{exercise}

\begin{exercise}
\code{let pi = 3.14159265359}$B$HF~NO$7!$(BEnter$B%-!<$r2!$7$F$_$h$&!%(B
\label{ex:def_pi}
\end{exercise}

\begin{exercise}
\exref{ex:def_pi}$B$r9T$C$?8e$G!$(B\code{pi}$B$H$$$&<0$rI>2A$9$k$H$I$&$J$k$@$m$&$+!)(B\break
\code{1.23 *. 1.23 *. pi}$B$d(B\code{2.0 *. 1.23 *. pi}$B$G$O$I$&$+!)(B
\end{exercise}

$BDj5A$r<B9T$9$k$H$-$b!$<0$NI>2A$N$H$-$HF1MM$K8e$K!V(B\texttt{;;}$B!W$rIU$1$F(BEnter$B%-!<$r2!$;$P$h$$!%(B
$B0J2<$G$ODj5A$r<B9T$9$k$H$-$b!$$7$P$7$P!V(B\texttt{;;}$B!W$r>JN,$9$k!%(B

\begin{exercise}
 \exref{ex:def_pi}$B$GDj5A$7$?JQ?t(B\code{pi}$B$rMQ$$$F!$(B
 $B2]Bj(B\ref{ex:def_pi_try}$B$r$d$j$J$*$7$F$_$h$&!%(B
\end{exercise}

% \begin{keypoint}{$BJQ?t$NDj5A(B}
%  \begin{alltt} 
%   let $BJQ?t(B = $B<0(B;;\end{alltt} 
% %   $BNc(B
% % \begin{alltt}
% % \system{\#} let v = 5;;
% % \system{v : int = 5}
% % \system{\#} v * 5;;
% % \system{- : int = 25}
% % \system{\#} let x = 2 * v;;
% % \system{x : int = 10}
% % \end{alltt}
% \end{keypoint}

\section{$B4X?t$N8F$S=P$7(B}

\begin{exercise}
$B<0(B\code{sqrt 5.0}$B$rI>2A$7$F$_$h$&!%(B
\code{sqrt 3.0}$B$d(B\code{sqrt 4.0}$B$G$O$I$&$+!)(B
\end{exercise}

\begin{note} $BIaDL$N?t3X$H0[$J$j!$(B
\ocaml $B$G$O(B\code{f(x)}$B$d(B\code{g(5)}$B$J$I$N3g8L$r>JN,$7$F!$(B
\code{f x}$B$d(B\code{g 5}$B$N$h$&$K=q$/$3$H$,$G$-$k!%(B
$B$?$@$7!$0z?t$,J#;($J;~$O3g8L$,I,MW!%<+?.$N$J$$$H$-$O3g8L$r$D$1$k$3$H!%(B
$B!J(B\code{sqrt 3.0 + 1.0}$B$O(B\code{sqrt (3.0 + 1.0)}$B$H!$(B
\code{(sqrt 3.0) + 1.0}$B$N$I$A$i$@$m$&$+!)!K(B
\end{note}

\begin{exercise}
$BJ?J}:,4X?t(B\code{sqrt}$B$NB>$K!$;03Q4X?t(B\code{sin}$B!$(B\code{cos}$B!$(B\code{tan}$B$J$I$b;H$&$3$H$,$G$-$k!J0z?t$NC10L$O%i%8%"%s!%(B$\pi$$B%i%8%"%s(B = $180{}^\circ$$B!K!%(B
\code{sin (pi /. 2.0)}$B$J$I$rI>2A$7$F!$$$$m$$$m$J3QEY$KBP$9$k;03Q4X?t$NCM$r(B
$B7W;;$7$F$_$h$&!%(B
\end{exercise}

\section{$B4X?t$NDj5A(B}

\begin{exercise}
$BH>7B(B 9.87 $B$H(B 6.54 $B$H(B 3.21$B$N1_$NLL@Q$r$=$l$>$l5a$a$F$_$h$&!%(B
\end{exercise}

\begin{exercise}
\code{let menseki r = r *. r *. pi;;}$B$HF~NO$7$F(BEnter$B%-!<$r2!$7$F$_$h$&!%(B
$B$I$&$J$k$@$m$&$+!)7?$O$I$&I=<($5$l$k$@$m$&$+!)(B
\end{exercise}

\begin{exercise}
\code{menseki 9.87}$B!$(B\code{menseki 6.54}$B!$(B\code{menseki 3.21}$B$r(B
$B$=$l$>$lI>2A$7$F$_$h$&!%(B
\end{exercise}

\begin{note}$B$b$7!$(B\texttt{pi}$B$NCM$rJQ99$7$?$i!J$J$s$H!*!K!$(B
\texttt{menseki}$B$NDj5A$b<B9T$7$J$*$9I,MW$,$"$k!%(B
$B0lHL$K!$JQ?t$d4X?t$NDj5A$rJQ99$7$?$i!$(B
$B$=$l$rMxMQ$7$F$$$kJQ?t$d4X?t$bDj5A$7$J$*$9I,MW$,$"$k!%(B
$B$3$N$3$H$O!$0J2<$+$i3NG'$G$-$k!%(B
\begin{programcode}
\system{\#} let half_pi = 0.5 *. pi;;
\system{val half_pi : float = 1.570796326795}
\system{\#} let pi = 3;;
\system{val pi : float = 3.}
\system{\#} half_pi;;
\system{- : float = 1.570796326795}
\system{\#} let half_pi = 0.5 *. pi;;
\system{val half_pi : float = 1.5}
\system{\#} half_pi;;
\system{val - : float = 1.5}
\end{programcode}
\end{note}

%\begin{programcode}
% \# let taiseki r = (4.0 /. 3.0) *. pi *. r *. r *. r ;;
% val taiseki : float -> float = <fun>
% \# taiseki 3.0;;
% - : float = 113.097335529240013
% \# let pi = 3.0;;
% val pi : float = 3.
% \# taiseki 3.0;;
% - : float = 113.097335529240013
% \# let taiseki r = (4.0 /. 3.0) *. pi *. r *. r *. r ;;
% val taiseki : float -> float = <fun>
% \# taiseki 3.0;;
% - : float = 113.097335529240013
% \# taiseki 3.0;;                                       
% - : float = 108.
%\end{programcode}


\begin{exercise}
$BF1MM$K!$1_$NH>7B$+$i<~$ND9$5$r5a$a$k4X?t(B\texttt{shuu}$B$rDj5A$7!$(B
$BH>7B(B 9.87 $B$H(B 6.54 $B$H(B 3.21$B$N1_$N<~$ND9$5$r$=$l$>$l5a$a$F$_$h$&!%(B
\end{exercise}

\section{$B%0%i%U%#%C%/%9(B}

\begin{exercise}
\code{\#load "graphics.cma"}$B$H(B\code{open Graphics}$B$r$=$l$>$l=gHV$K<B9T$7$F$+$i!$(B
\code{open\us{}graph ""}$B$H(B\code{draw\us{}circle 100 100 50}$B$r$=$l$>$l=gHV$K<B9T$7$F$_$h$&!%2?$,5/$3$C$?$+!)(B
\keywords{$B%i%$%V%i%j!$%b%8%e!<%k!$(B{\tt unit}$BCM(B\code{()}$B$H(B{\tt unit}$B7?(B}
\end{exercise}

\begin{exercise}
$B4X?t(B\texttt{draw\us{}circle}$B$N0z?t$r$$$m$$$mJQ$($F<B9T$9$k$3$H$G!$(B
$B$I$N0z?t$,2?$rI=$7$F$$$k$+?dB,$7$F$_$h$&!%(B
\end{exercise}

\begin{exercise}
WWW$B%V%i%&%6$G!$0J2<$N<j=g$K$h$j(B\ocaml{}$B$N(B\texttt{Graphics}$B%b%8%e!<%k$N%^%K%e%"%kF|K\8lLu$r3+$$$F!$(B
$B4X?t(B\texttt{draw\us{}circle}$B$N@bL@$rC5$7$FFI$s$G$_$h$&!%(B
\begin{enumerate}
 \item \url{http://ocaml.jp/}$B$r3+$/!%(B
 \item $B:8%a%K%e!<$+$i!V%^%K%e%"%k!W$N%j%s%/$rC)$k!%(B
 \item $B!V0JA0$N%P!<%8%g%s!W$N%j%9%H$NCf$+$i!$!V(B3.06($BOBLuHG(B)$B!W$N%j%s%/$rC)$k(B\footnote{$BK\8&=$$G;HMQ$9$k(B\ocaml{}$B$N%P!<%8%g%s$O(B3.11.0$B$G$"$k$,!$(B3.11.0$B$N(B\texttt{Graphics}$B%b%8%e!<%k$N%^%K%e%"%k$NF|K\8lLu$O$^$@$5$l$F$$$J$$!%(B3.11.0$B$N(B\texttt{Graphics}$B%b%8%e!<%k$N%^%K%e%"%k$H(B
3.06$B$N(B\texttt{Graphics}$B%b%8%e!<%k$N%^%K%e%"%k$K$OBg$-$J0c$$$O$J$$$?$a!$:#2s$O(B3.06$B$N%^%K%e%"%k$rMxMQ$9$k!%(B}$B!%(B
 \item $B!V(BPart IV Objective Caml $B%i%$%V%i%j!W$N!V(BThe graphics library$B!W$N%j%s%/$rC)$k!%(B
 \item $B%Z!<%82<It!V(BModule Graphics: machine-independent graphics primitives$B!W$N%j%s%/$rC)$k!%(B
\end{enumerate}
$B!J>e$NBe$o$j$KD>@\(B
\url{http://ocaml.jp/archive/ocaml-manual-3.06-ja/libref/Graphics.html}$B$r3+$$$?$N$G$b$h$$!%!K(B
\end{exercise}

\begin{exercise}
$B4X?t(B\texttt{draw\us{}rect}$B!$(B
\texttt{draw\us{}ellipse}$B!$(B
\texttt{draw\us{}arc}$B!$(B
\texttt{fill\us{}rect}$B!$(B
\texttt{fill\us{}circle}$B!$(B
\texttt{fill\us{}ellipse}$B!$(B
\texttt{fill\us{}arc}$B$N@bL@$rFI$s$G!$$=$l$>$l$r<B:]$K;H$C$F$_$h$&!%(B
$B2hLL$,%4%A%c%4%A%c$7$F$-$?$i!$(B\code{clear\us{}graph ()}$B$r<B9T$9$k$3$H$G!$(B
$B2hLL$r%/%j%"$G$-$k!%(B
\end{exercise}

\begin{exercise}
$B4X?t(B\texttt{set\us{}color}$B$K(B\texttt{color}$B7?$NCM(B\texttt{red}$B!$(B\texttt{blue}$B!$(B
\texttt{green}$B$J$I$rM?$($F<B9T$7$_$h$&!%$=$l$+$i!$(B\texttt{draw\us{}cicle}$B$J$I$r(B
$B8F$S=P$9$H$I$&$J$k$@$m$&$+!)(B
$B!J$"$i$+$8$aMQ0U$5$l$F$$$k?'L>$O!$%^%K%e%"%k$N!V(BSome predefined colors$B!W$r8+$h!%(B
$B$=$l0J30$N?'$rMxMQ$7$?$$$H$-$O!$4X?t(B\texttt{rgb}$B$rMxMQ$;$h!%(B
$B$?$H$($P(B\code{let gray = rgb 128 128 128}$B$d(B\code{let violet = rgb 238 130 238}$B$J$I!%!K(B
\end{exercise}




\begin{exercise}
$B4X?t(B\texttt{moveto}$B$H4X?t(B\texttt{lineto}$B$N@bL@$rFI$_!$<B:]$K;H$C$F$_$h$&!%(B
$B$?$H$($P!$!_0u$rIA$$$F$_$h$&!%(B
\end{exercise}

\begin{exercise}
$B@0?t(B$x$$B$H(B$y$$B$r<u$1$H$j!$:BI8(B$(x,y)$$B$r:82<$H$9$k0lJU$ND9$5$,(B$100$$B$N@5J}7A$r(B
$BIA$/4X?t(B\texttt{square}$B$rDj5A$7$F$_$h$&!%(B
\begin{hint}
$B4X?t(B\texttt{square}$B$O0z?t$rFs$D$H$k$N$G!$(B
\code{let square x y = }$B$N$h$&$K=q$-;O$a$k!%(B
\end{hint}
\begin{hint}
$B4X?t(B\texttt{draw\us{}rect}$B$rMQ$$$k!%(B
\end{hint}
\end{exercise}

\begin{exercise}
$B@0?t(B$x$$B$H(B$y$$B$r<u$1$H$j!$:BI8(B$(x,y)$$B$r>e$ND:E@$H$9$k@5;03Q7A!J0lJU$ND9$5(B$100$$B!$DlJU$O(B$x$$B<4$KJ?9T!K$rIA$/4X?t(B\texttt{triangle}$B$rDj5A$7$h$&!%(B
$B$?$@$7!$@0?t$r>.?t$K$9$k$K$O(B\texttt{float\us{}of\us{}int}$B$r!$>.?t$r@0?t$K$9$k$K$O(B
\texttt{int\us{}of\us{}float}$B$r$=$l$>$lMQ$$$k!%$^$?!$J#?t$N<0$r=g$K<B9T$9$k$K$O!$(B
\code{ ${$B<0(B}\sb{1}$; ${$B<0(B}\sb{2}$;{}\ldots{};${$B<0(B}\sb{n}$}$B$N$h$&$K=q$1$P$h$$!%(B
\begin{hint}
$B0lJU$ND9$5$,(B$l$$B$N@5;03Q7A$N9b$5$O!$(B$(\sqrt{3}/2) l$$B!%(B
\end{hint}
\label{ex:triangle}
\end{exercise}

\begin{exercise}
\exref{ex:triangle}$B$GDj5A$7$?4X?t(B\texttt{triangle}$B$r(B
$B0lJU$ND9$5(B$l$$B$b0z?t$H$7$F<h$k$h$&3HD%$7$F$_$h$&!%(B
\begin{hint}
 \code{let triangle x y l = }$B$N$h$&$K=q$-;O$a$k!%(B
\end{hint}
\end{exercise}

\section{$B7+$jJV$7(B/$BH?I|(B/$B%k!<%W(B}

\begin{exercise}
\code{clear\us{}graph ()}$B$r<B9T$72hLL$r%/%j%"$7$F$+$i!$(B
$B<!$r<B9T$7$F$_$h$&!%(B
\begin{programcode}
for i = 1 to 10 do 
  draw_circle 100 100 (10 * i)
done
\end{programcode}
$B!J(B\ocaml{}$B$N%W%m%0%i%`$O!$C18l$NESCf0J30$G$"$l$P$I$3$G$b2~9T$7$F$h$$!%0J2<F1MM!%!K(B
$B$I$s$J3($,IA$1$?$+!)(B\keywords{$B7+$jJV$7(B/$BH?I|(B/$B%k!<%W(B}
\label{ex:loop}
\end{exercise}

\begin{exercise}
\exref{ex:loop}$B$N%W%m%0%i%`Cf$N?t;z$d4X?t!J(B\texttt{draw\us{}circle}$B!K$r(B
$B$$$m$$$m$KJQ$($F!$$I$&$J$k$+;n$7$F$_$h$&!%(B
\end{exercise}

\begin{figure}
\begin{itembox}[l]{\textbf{$B%_%K%.%c%i%j!<!'%0%i%G!<%7%g%s(B}}
\small
\begin{center}\resizebox{150pt}{!}{\includegraphics{gradation_rect.eps}}\end{center}
\begin{programcode}
let gradation_rect x y w h = 
   for i = 0 to h do 
     for j = 0 to w do
        let fj = float_of_int j in 
        let fi = float_of_int i in 
        let fw = float_of_int w in 
        let fh = float_of_int h in 
        set_color (rgb (int_of_float (255. *. fj /. fw))
                       255 
                       (int_of_float (255. *. fi /. fh)));
        plot (x+j) (y+i);
     done  
   done
\end{programcode}
$B$?$@$7!$(B\code{let x = ${$B<0(B}\sb{1}$ in ${$B<0(B}\sb{2}$}$B$O!$(B
$BDj5A(B\code{let x = ${$B<0(B}\sb{1}$}$B$N$b$H$G(B
${$B<0(B}\sb{2}$$B$rI>2A$9$k$3$H$rI=$9!%(B
\end{itembox}
\end{figure}

\section{$B:F5"(B}
\label{sec:recursion}
\begin{exercise}
\code{clear\us{}graph ()}$B$r<B9T$72hLL$r%/%j%"$7$F$+$i!$(B
$B<!$N4X?tDj5A$r<B9T$7$h$&!%(B
\begin{programcode}
let rec f x =
    if x < 1 then 
        ()
    else
        (draw_circle 100 100 x; f (x/2)) 
\end{programcode}
$B$=$N8e!$(B\code{f 100}$B$rI>2A$7$F$_$h$&!%(B
$B$I$s$J3($,IA$1$?$+!)(B
$B$3$3$G!$(B
\begin{programcode}
 if \({$B<0(B}\sb{1}\) then \({$B<0(B}\sb{2}\) else \({$B<0(B}\sb{3}\)
\end{programcode}
$B$O!$(B${$B<0(B}_1$$B$,@.$jN)$F$P(B${$B<0(B}_2$$B$r!$@.$jN)$?$J$1$l$P(B${$B<0(B}_3$$B$r<B9T$9$k(B
$B$H$$$&0UL#$N<0$G$"$k!%(B
\keywords{$B:F5"!$>r7oJ,4t(B}
\label{ex:recursion}
\end{exercise}

\begin{exercise}
\exref{ex:recursion}$B$N(B\code{if x < 1 then () else}$B$NItJ,$rK:$l$F(B
\begin{programcode}
let rec f x =
    (draw_circle 100 100 x; f (x/2)) 
\end{programcode}
$B$HDj5A$7$F$7$^$$!$(B\code{f 100}$B$rI>2A$9$k$H$I$&$J$k$+!)(B
\begin{note}
$B<B9T$rCf;_$7$?$$$H$-$O!$(B\texttt{Ctrl}$B%-!<$r2!$7$J$,$i!$(B\texttt{c}$B$r2!$9!%(B
\end{note}
\end{exercise}



\clearpage
%\section*{$B2]Bj(B}

\part*{$B2]Bj(B}

\begin{screen}
\ocaml{}$B$N5!G=$rMxMQ$7$F!$2?$+9%$-$J3($rIA$$$F$_$h$&!%(B
\ref{sec:recursion}$B>O$^$G$K=P$F$-$?$$$m$s$J5!G=$r$G$-$k$@$1MxMQ$9$k$3$H!%(B
\end{screen}

\subsection*{$BDs=PJ}K!(B}
\emph{$B$G$-$?3((B}$B$H!$(B\emph{$B$=$N3($rIA$/$N$K(B
  $BMQ$$$?%W%m%0%i%`A4It!J<0$dJQ?tDj5A!&4X?tDj5A!K(B}$B$r!$(B
\url{kztk@kb.ecei.tohoku.ac.jp}$B$K%a!<%k$GAw$k!%(B
$B$3$3$G!$(B
\begin{itemize}
 \item $B7oL>$O!VAOB$9)3X8&=$(B2010$B!'>>ED0l9'!W$N$h$&$K!$(B
$B!VAOB$9)3X8&=$(B2010$B!'!W$N8e$K<+J,$NL>A0$r$D$E$1$?$b$N!%(B
 \item $B3($*$h$S%W%m%0%i%`$O%a!<%k$KE:IU!%(B
 \item $B%W%m%0%i%`$N%U%!%$%kL>$O!V(B\texttt{\mbox{$BL>A0(B}\us{}\mbox{$BL>;z(B}.ml}$B!W!$(B
   $B3($N%U%!%$%kL>$O!V(B\texttt{\mbox{$BL>A0(B}\us{}\mbox{$BL>;z(B}.bmp}$B!W!%(B
\end{itemize}
$B$H$;$h!%(B

\subsection*{$B%W%m%0%i%`$N<B9TJ}K!$H3($NJ]B8J}K!(B}

$B%W%m%0%i%`$O%a%bD"!J!V%9%?!<%H!W"*!V$9$Y$F$N%W%m%0%i%`!W"*!V%"%/%;%5%j!W"*!V%a%bD"!W!K(B
$B$J$I$G=q$$$F$+$i!$(B\texttt{ocaml}$B$K%3%T!<(B\&$B%Z!<%9%H$9$k$H$h$$!%(B
$B!J%a%bD"$G%3%T!<$7$?$$HO0O$r%I%i%C%0$7$FA*Br$7!VJT=8!W"*!V%3%T!<!W!$(B
$B$=$N8e%3%^%s%I%W%m%s%W%H$G:8>e$N%"%$%3%s$r%/%j%C%/$7$F!VJT=8!W"*!VE=$jIU$1!W!K(B
$B$3$NJ}K!$@$H!$%W%m%0%i%`$rJ]B8$9$k$N$b$N!V%U%!%$%k!W"*!VL>A0$r$D$1$FJ]B8!W$+$i2DG=$G$"$k!%(B

$B3($r%U%!%$%k$KJ]B8$9$k$K$O!$!V(BCaml Graphics$B!W$N%&%#%s%I%&$,:GA0LL$K=P$F$$$k>uBV$G!$(B
\texttt{Alt}$B$r2!$7$J$,$i(B\texttt{PrintScreen}$B%-!<$r2!$9!%$=$N8e!$(B
$B%Z%$%s%H!J!V%9%?!<%H!W"*!V$9$Y$F$N%W%m%0%i%`!W"*!V%"%/%;%5%j!W"*!V%Z%$%s%H!W!K$r5/F0$7$F!$(B
$B!VJT=8!W"*!VE=$jIU$1!W8e!$!V%U%!%$%k!W"*!VL>A0$r$D$1$FJ]B8!W$H$9$l$P$h$$!%(B






\clearpage
\appendix
\part*{$BIUO?(B}

\section{$B%M%C%H%o!<%/%W%m%0%i%_%s%0$=$N(B1$B!'(BHTTP}

\begin{exercise}
\code{\#load "unix.cma"}$B!$(B\code{open Unix}$B$r$=$l$>$l<B9T$7$F!$(B
\texttt{Unix}$B%b%8%e!<%k!J%i%$%V%i%j!K$r%m!<%I$7$h$&!%(B
\end{exercise}

Unix$B$H$O%*%Z%l!<%F%#%s%0%7%9%F%`!J(BOS$B!K$NL>A0$G$"$k!%(B
$B$$$o$f$k%$%s%?!<%M%C%H$G;HMQ$5$l$F$$$k(BTCP/IP$BDL?.J}<0$O!$(BUnix$B$rCf?4$KH/E8$7$F$-$?!%(B
$B8=:_$G$O!$(BUnix$B0J30$N(BOS$B$K$b(BUnix$B$HF1MM$N(BTCP/IP$BDL?.5!G=$,$"$k!%(B

$B%$%s%?!<%M%C%H$G$O!$(B\url{www.tohoku.ac.jp}$B$N$h$&$J?M4V$K$o$+$j$d$9$$L>A0!J%[%9%HL>!K(B
$B$N$[$+$K!$(B
\texttt{208.77.188.166}$B$N$h$&$J?t;z$N%"%I%l%9!J(BIP$B%"%I%l%9!K$,$"$k!%(B

\begin{exercise}
\code{let host = gethostbyname "www.tohoku.ac.jp"}$B$*$h$S(B
\code{let addr = h.addr\us{}list.(0)}$B$r<B9T$7$F$_$h$&!%(B
$B$5$i$K!$(B\code{string\us{}of\us{}inet\us{}addr addr}$B$rI>2A$7$F$_$h$&!%(B
$B$I$s$J7k2L$,I=<($5$l$?$+!)(B
\end{exercise}

% # let host = gethostbyname "www.tohoku.ac.jp";;
% val host : Unix.host_entry =
%   {h_name = "toppage.bureau.tohoku.ac.jp";
%    h_aliases = [|"www.tohoku.ac.jp"|]; h_addrtype = PF_INET;
%    h_addr_list = [|<abstr>|]}
% # let addr = host.h_addr_list.(0);;
% val addr : Unix.inet_addr = <abstr>
% # string_of_inet_addr addr;;
% - : string = "130.34.15.80"

$B$$$o$f$k%$%s%?!<%M%C%H$N!V%[!<%`%Z!<%8!W$O(BHTML$B$H$$$&8@8l$G5-=R$5$l$F$$$k!%(B

\begin{exercise}
WWW$B%V%i%&%6$G!$(B
\url{http://www.tohoku.ac.jp/english/}$B$r3+$-!$(B
$B1&%/%j%C%/$r$7!V%Z!<%8$N%=!<%9$rI=<(!W$7$F$_$h$&!%(B
\end{exercise}

\begin{exercise}
$B0J2<$NDj5A$d<0$r=g$K<B9T$J$$$7I>2A$7$F$_$h$&!%(B
\begin{programcode}
let (ic, oc) = open_connection (ADDR_INET(addr, 80));;
output_string oc "GET /english/ HTTP/1.0\bs{}r\bs{}n";;
output_string oc "Host www.tohoku.ac.jp\bs{}r\bs{}n\bs{}r\bs{}n";;
flush oc;;
print_endline (input_line ic);;
print_endline (input_line ic);;
 \vdots {\rm \raisebox{2pt}{\mbox{($B$7$P$i$/>e5-%3%^%s%I$r7+$jJV$9!%%3%T!<(B\&$B%Z!<%9%H$7$h$&!%(B)}}}
print_endline (input_line ic);;
close_in ic;;
\end{programcode}
\end{exercise}

$B0lHL$K(BWWW$B%V%i%&%6$O!$$3$N$h$&$K$7$F%@%&%s%m!<%I$7$?(BHTML$BJ8=q$r2r@O!&IA2h$9$k$3$H$G!$(B
$B%[!<%`%Z!<%8$rI=<($7$F$$$k!%(B

\section{$B%M%C%H%o!<%/%W%m%0%i%_%s%0$=$N(B2$B!'(BSMTP}


\begin{exercise}
$B0J2<$NDj5A$d<0$r=g$K<B9T$J$$$7I>2A$7$F$_$h$&!%(B
$BAw?.85$OElKLBg3X$G$N<+J,$N%a!<%k%"%I%l%9!$Aw?.@h$O<+J,$N7HBS$N%a!<%k%"%I%l%9$K$7$h$&!%(B
$B$b$77HBSEEOC$N%a!<%k%"%I%l%9$r$b$C$F$J$1$l$P!$<+J,$NB>$N%a!<%k%"%I%l%9$G$b$h$$!%(B
\emph{$B7h$7$FB>?M$N%a!<%k%"%I%l%9$r;HMQ$7$J$$$3$H(B}$B!%(B
\begin{programcode}
let host = gethostbyname "primergy.kb-private";;
let addr = host.h_addr_list.(0);;
let (ic, oc) = open_connection(ADDR_INET(addr,25));;
print_endline (input_line ic);;
output_string oc "HELO localhost\bs{}r\bs{}n";;
flush oc;;
print_endline (input_line ic);;
output_string oc "MAIL FROM: \textcolor{blue}{\mbox{$BAw?.85%a!<%k%"%I%l%9(B}}\bs{}r\bs{}n";;
flush oc;;
print_endline (input_line ic);;
output_string oc "RCPT TO: \textcolor{blue}{\mbox{$BAw?.@h%a!<%k%"%I%l%9(B}}\bs{}r\bs{}n";;
flush oc;;
print_endline (input_line ic);;
output_string oc "DATA\bs{}r\bs{}n";;
flush oc;;
print_endline (input_line ic);;
output_string oc "From: \textcolor{blue}{\mbox{$BAw?.85%a!<%k%"%I%l%9(B}}\bs{}r\bs{}n";;
output_string oc "To: \textcolor{blue}{\mbox{$BAw?.@h%a!<%k%"%I%l%9(B}}\bs{}r\bs{}n";;
output_string oc "Subject: test mail\bs{}r\bs{}n";;
output_string oc "this is a test\bs{}r\bs{}n";;
output_string oc ".\bs{}r\bs{}n";;
flush oc;;
print_endline (input_line ic);;
output_string oc "quit\bs{}r\bs{}n";;
flush oc;;
print_endline (input_line ic);;
close_in ic;;
\end{programcode}
\label{ex:send-mail}
\end{exercise}

\begin{exercise}
\exref{ex:send-mail}$B$K$*$$$F!$!VAw?.85%a!<%k%"%I%l%9!W$K(B
\texttt{dummy@example.com}$B!J<B:_$7$J$$!K$r;XDj$7$?$i$I$&$J$k$+!)(B
\end{exercise}


\section{3D$B%W%m%0%i%_%s%0(B}

\begin{exercise}
\ocaml $B$r=*N;$7!$(B\texttt{ocaml}$B$N$+$o$j$K(B
\texttt{lablglut}$B$r5/F0$7$F$+$i!$(B
$B0J2<$NDj5A$d<0$r=g$K<B9T$J$$$7I>2A$7$h$&!%(B
\texttt{(*}$B$H(B\texttt{*)}$B$G0O$^$l$?ItJ,$O%3%a%s%H$J$N$GF~NO$7$J$/$F$b$h$$!%(B

\begin{note}
$B!V(B\texttt{`}$B!W$O%P%C%/%/%)!<%H$H$$$&5-9f$G!$(B
$BI8=`E*$JF|K\8l%-!<%\!<%I$G$O!$(B
\texttt{Shift}$B%-!<$r2!$7$J$,$i(B\texttt{@}$B%-!<$r2!$;$PF~NO$G$-$k!%(B
$B!V(B\texttt{'}$B!W!J%/%)!<%H!K$H$O0[$J$k$N$G5$$r$D$1$k$3$H!%(B
$B!V(B\texttt{\chartilde}$B!W$O%A%k%@$H$$$&5-9f$G!$(B
$BI8=`E*$JF|K\8l%-!<%\!<%I$G$O!$(B
\texttt{Shift}$B%-!<$r2!$7$J$,$i(B\texttt{\charhat}$B%-!<$r2!$;$PF~NO$G$-$k!%(B
\end{note}

\begin{programcode}
(* $B=i4|2==hM}(B *) 
Glut.init Sys.argv;;

(* $B%&%$%s%I%&$N=`Hw(B *) 
Glut.createWindow "kisozemi";;

(* $B%i%$%H$rM-8z2=(B *) 
Gl.enable `lighting;; 

(* 1$BHV$N%i%$%H$rGr?'$N4D6-8w$K@_Dj(B *) 
GlLight.light 1 (`ambient (1.0, 1.0, 1.0, 1.0));; 
(* 1 $BHV$N%i%$%H$rM-8z2=(B *) 
Gl.enable `light1;; 
(* 2 $BHV$N%i%$%H$r@V?'$NE@8w8;$K@_Dj(B *) 
GlLight.light 2 (`diffuse (1.0, 0.0, 0.0, 1.0));; 
(* 2 $BHV$N%i%$%H$r1&J}$K@_CV(B *) 
GlLight.light 2 (`position (2.0, 0.0, 0.0, 0.0));; 
(* 2 $BHV$N%i%$%H$rM-8z2=(B *) 
Gl.enable `light2;; 
(* 3 $BHV$N%i%$%H$r@D?'$NE@8w8;$K@_Dj(B *)
GlLight.light 3 (`diffuse (0.0, 0.0, 1.0, 1.0));; 
(* 3 $BHV$N%i%$%H$r:8J}$K@_CV(B *) 
GlLight.light 3 (`position (-2.0, 0.0, 0.0, 0.0));; 
(* 3 $BHV$N%i%$%H$rM-8z2=(B *)
Gl.enable `light3;;

(* $BIA2h4X?t(B *) 
let rec display () =
  (* $B2hLL$r%/%j%"$9$k$H$-$N?'$r9u$K@_Dj(B *) 
  GlClear.color (0.0, 0.0, 0.0);
  (* $B2hLL$r%/%j%"(B *) 
  GlClear.clear [`color];
  (* $B%5%$%:(B 0.5 $B$N%F%#!<%]%C%H$rIA2h(B *) 
  Glut.solidTeapot 0.5; 
  (* $B%P%C%U%!$r%U%i%C%7%e(B *) 
  Gl.flush ();;

(* $BIA2h4X?t$rEPO?(B *) 
Glut.displayFunc display;;

(* $B%-!<%\!<%I=hM}4X?t(B *) 
let keyboard ~key:k ~x:x ~y:y =
  (* $B%F%#!<%]%C%H$r2sE>(B *) 
  GlMat.rotate ~angle:2.0 ~x:0.25 ~y:0.5 ~z:1.0 (); 
  (* $BIA2h4X?t(B display $B$r8F$S=P$7$FA42hLL$r:FIA2h(B *) 
  display ();;

(* $B%-!<%\!<%I=hM}4X?t$rEPO?(B *) 
Glut.keyboardFunc keyboard;;

(* $B%a%$%s%k!<%A%s$r5/F0(B *) 
Glut.mainLoop ();;
\end{programcode}
$B0J>e$r$9$Y$F<B9T$9$k$H!$(B
$B!V(B\texttt{kisozemi}$B!W%&%#%s%I%%$,=P$F$/$k$N$G%9%Z!<%9%-!<$J$IE,Ev$J%-!<$r(B
$B2?EY$b2!$7$F$_$h$&!%(B
$B=*N;$9$k$H$-$O!V%3%^%s%I%W%m%s%W%H!W%&%$%s%I%&1&>e$N!_%\%?%s$G%&%$%s%I%&$rJD$8$l$P$h$$!%(B
\end{exercise}


\section{$B%^%&%9$H%-!<%\!<%I$+$i$NF~NO(B\\$B$*$h$S%l%3!<%I$H%P%j%"%s%H$K$D$$$F(B}

\begin{exercise}
\code{\#load "graphics.cma"}$B!$(B\code{open Graphics}$B!$(B\code{open\us{}graph ""}
$B$r=g$K<B9T$7$F$+$i!$(B\code{wait\us{}next\us{}event [Button\us{}down]}$B$r<B9T$7$?8e!$(B
\texttt{Caml graphics}$B%&%#%s%I%&$NCf$NE,Ev$J0lE@$r%/%j%C%/$7$F$_$h$&!%(B
$B%/%j%C%/$9$k0LCV$K$h$C$F!$JV$jCM$O$I$N$h$&$KJQ2=$9$k$@$m$&$+!)(B
\keywords{$B%l%3!<%I!$%i%Y%k(B}
\end{exercise}

\begin{exercise}
$BF1MM$K(B\code{let s = wait\us{}next\us{}event [Button\us{}down]}$B$r<B9T$7$F$+$i!$(B
$B!J(B\texttt{Caml graphics}$B%&%#%s%I%&$NCf$NE,Ev$J0lE@$r%/%j%C%/$7$?8e$G!K(B
\code{s.mouse\us{}x}$B!$(B\code{s.mouse\us{}y}$B$r$=$l$>$lI>2A$7$F$_$h$&!%(B
\keywords{$B%U%#!<%k%I!$%U%#!<%k%ICM$N<h$j=P$7(B}
\end{exercise}

\begin{exercise}
 \code{let s = wait\us{}next\us{}event [Key\us{}pressed]}$B$r<B9T$7$F$+$i!$(B
\texttt{Caml graphics}$B%&%#%s%I%&$GE,Ev$J%-!<$r2!$7!$$=$N8e$G(B
\code{s.key}$B$rI>2A$7$F$_$h$&!%(B
\keywords{$B%P%j%"%s%H!$9=@.;R(B}
\end{exercise}

\begin{exercise}
\code{let s = wait\us{}next\us{}event [Key\us{}pressed;Button\us{}down]}$B$N>l9g$O$I$&$+!)(B
$B%^%&%9$r%/%j%C%/$7$?>l9g$H%-!<$r2!$7$?>l9g$NN>J}$r;n$7$F$_$h$&!%(B
\keywords{$B%j%9%H(B}
\end{exercise}

\section{$B%j%9%H$HG[Ns(B}

$B$I$A$i$b!V!JF1$87?$N!KJ#?t$NCM$r=gHV$KJB$Y$F0l$D$K$^$H$a$?CM!W!%(B

\subsection*{$B%j%9%H$HG[Ns$N=q$-J}(B}

$B%j%9%H$O(B\texttt{[}$B$G;O$^$j!$(B\texttt{;}$B$G6h@Z$C$F!$(B\texttt{]}$B$G=*$o$k!%(B
\begin{programcode}
\system{\#} [ 1 ; 2 ; 3 ];;
\system{- : int list = [1; 2; 3] }
\system{\#} [ 3 ; 2 ; 1 ];;     (* $B=gHV$O6hJL$9$k(B *) 
\system{- : int list = [3; 2; 1] }
\system{\#} [ 1 ; 1 ; 2 ; 3 ];; (* $B=EJ#$b6hJL$9$k(B *) 
\system{- : int list = [1; 1; 2; 3]}
\end{programcode}

$BG[Ns$O(B\texttt{[|}$B$G;O$^$j!$(B\texttt{;}$B$G6h@Z$C$F!$(B\texttt{|]}$B$G=*$o$k!%(B
\begin{programcode}
\system{\#} [| 1 ; 2 ; 3 |];;
\system{- : int array = [|1; 2; 3|] }
\system{\#} [| 3 ; 2 ; 1 |];;     (* $B=gHV$O6hJL$9$k(B *) 
\system{- : int array = [|3; 2; 1|] }
\system{\#} [| 1 ; 1 ; 2 ; 3 |];; (* $B=EJ#$b6hJL$9$k(B *) 
\system{- : int array = [|1; 1; 2; 3|]}
\end{programcode}

\subsection*{$B%j%9%H$HG[Ns$KBP$9$kA`:n(B}

\subsubsection*{$B%j%9%H$KBP$9$kA`:n(B}


\begin{description}
\item[\texttt{x :: ys}]~\\
$B0l$D$N(B\emph{$BMWAG(B}\texttt{x}$B$r!$%j%9%H(B\texttt{ys}$B$N@hF,$KDI2C$7$?%j%9%H$rJV$9!%(B

\begin{programcode}
\system{\#} let ys = [ 1 ; 2 ; 3 ];;
\system{val ys : int list = [1; 2; 3] }
\system{\#} 4 :: ys;;
\system{- : int list = [4; 1; 2; 3] }
\end{programcode}

\item[\texttt{xs @ ys}]~\\
\emph{$B%j%9%H(B}\texttt{xs}$B$N8e$m$K%j%9%H(B\texttt{ys}$B$rO"7k$7$?%j%9%H$rJV$9!%(B


\begin{programcode}
\system{\#} let xs = [ 1; 2; 3; ];;
\system{val xs : int list = [1; 2; 3]}
\system{#} let ys = [ 4; 5; 6; ];;
\system{val ys : int list = [4; 5; 6]}
\system{#} xs @ ys;;
\system{- : int list = [1; 2; 3; 4; 5; 6]}
\end{programcode}

\item[\texttt{match \(\mathit{xs}\) with [] -> \({$B<0(B}\sb{1}\) | x::ys -> \($B<0(B\sb{2}\) }]~\\
  $B%j%9%H(B$\mathit{xs}$$B$rD4$Y!$(B
$B6u%j%9%H(B$\texttt{[]}$$B$G$"$C$?$J$i$P(B${$B<0(B}\sb{1}$$B$rI>2A$9$k!%(B
$B6u$G$J$1$l$P!$@hF,$NMWAG$r(B\texttt{x}$B!$$=$l0J30$N;D$j$N%j%9%H$r(B$\texttt{ys}$$B$H$7$F!$(B
${$B<0(B}\sb{2}$$B$rI>2A$9$k!%(B

\begin{programcode}
\system{#} let e = [];;
\system{val e : 'a list = []}
\system{#} match e with [] -> "empty" | x::ys -> "non-empty";;
\system{- : string = "empty"}
\system{#} let xs = [1;2;3];;
\system{val xs : int list = [1; 2; 3]}
\system{#} match xs with [] -> -1 | x::ys -> x;;
\system{- : int = 1}
\system{#} match xs with [] -> [] | x::ys -> ys;;
\system{- : int list = [2; 3]}
\end{programcode}

$B%j%9%H$,6u$G$J$$3N?.$,$"$l$P!$(B\texttt{[] -> \({$B<0(B}\sb{1}\) |}
$B$NItJ,$r>JN,$7$F$b$h$$!%!J$?$@$77Y9p$,$G$k!%!K(B

\begin{programcode}
\system{#} {match xs with x::ys -> ys};;
\system{Characters 0-27:
  match xs with x::ys -> ys;;
  ^^^^^^^^^^^^^^^^^^^^^^^^^
Warning P: this pattern-matching is not exhaustive.
Here is an example of a value that is not matched:
[]
- : int list = [2; 3]}
\end{programcode}

$B%j%9%H$,6u$N$H$-(B\texttt{[] -> \({$B<0(B}\sb{1}\) |}
$B$NItJ,$r>JN,$9$k$H%(%i!<!JNc30!K$,5/$3$j!$!JNc30=hM}$7$J$1$l$P!K%W%m%0%i%`$N<B9T$,Cf;_$5$l$k!%(B

\begin{programcode}
\system{#} match e with x::ys -> ys;; 
\system{Characters 0-26:
  match e with x::ys -> ys;;
  ^^^^^^^^^^^^^^^^^^^^^^^^
Warning P: this pattern-matching is not exhaustive.
Here is an example of a value that is not matched:
[]
Exception: Match_failure ("", 1, 0).}
\end{programcode}
\end{description}


\subsubsection*{$BG[Ns$KBP$9$kA`:n(B}
\begin{description}
\item[\texttt{a.(i)}]~\\
$BG[Ns(B\texttt{a}$B$N(B\texttt{i}$BHVL\$NMWAG$rJV$9!%(B

\begin{programcode}
\system{#} let a = [| "apple"; "orange"; "banana" |];;
\system{val a : string array = [|"apple"; "orange"; "banana"|]}
\system{#} a.(0);;
\system{- : string = "apple"}
\system{#} a.(1);;
\system{- : string = "orange"}
\system{#} a.(2);;
\system{- : string = "banana"}
\end{programcode}

\item[\texttt{a.(i) <- x}]~\\
$BG[Ns(B\texttt{a}$B$N(B\texttt{i}$BHVL\$NMWAG$r(B\texttt{x}$B$G>e=q$-$9$k!J$3$N<0<+BN$NJV$jCM$O(B\texttt{unit}$B!K!%(B

\begin{programcode}
\system{#} let a = [| "apple"; "orange"; "banana" |];;
\system{val a : string array = [|"apple"; "orange"; "banana"|]}
\system{#} a.(1) <- "melon";;
\system{- : unit = ()}
\system{#} a;;
\system{- : string array = [|"apple"; "melon"; "banana"|]}
\end{programcode}

\item[\texttt{Array.make n x}]~\\
$BMWAG?t$,(B\texttt{n}$B$G!$A4MWAG$,(B\texttt{x}$B$G$"$k$h$&$JG[Ns$r?7$?$K:n$C$FJV$9!%(B

\begin{programcode}
\system{#} let a = Array.make 8 0.5;;
\system{val a : float array = [|0.5; 0.5; 0.5; 0.5; 0.5; 0.5; 0.5; 0.5|]}
\system{#} a.(1) <- 3.;;
\system{- : unit = ()}
\system{#} a;;
\system{- : float array = [|0.5; 3.; 0.5; 0.5; 0.5; 0.5; 0.5; 0.5|]}
\end{programcode}

\end{description}


\subsection*{$B%j%9%H$HG[Ns$N0c$$!J(B\ocaml $B$N>l9g!K(B}

\paragraph{$B%j%9%H(B}
\begin{itemize}
 \item $B%j%9%H$O(B\texttt{::}$B$G!V0l$D$NMWAG$r@hF,$KDI2C$7$?%j%9%H!W$r:n$k$N$,MF0W!%(B
 \item $B%j%9%H$O(B\texttt{match}$B$G!V@hF,$NMWAG$H$=$l0J30$N;D$j$N%j%9%H!W$r<h$j=P$9$N$,MF0W!%(B
\end{itemize}


\paragraph{$BG[Ns(B}
\begin{itemize}
 \item $BG[Ns$OG$0U$N(B\texttt{i}$B$K$D$$$F!V(B\texttt{i}$BHVL\$NMWAG!W$r9bB.$K<h$j=P$9$3$H$,$G$-$k!%(B
   $B!J%j%9%H$G$b(B\texttt{List.nth xs i}$B<h$j=P$9$3$H$O2DG=$G$"$k$,!$(B\texttt{i}$B$,Bg$-$$$H;~4V$,$+$+$k!K(B
 \item $BG[Ns$OMWAG$r(B\emph{$B>e=q$-(B}$B$9$k$3$H$,$G$-$k!J%j%9%H$O$G$-$J$$!K!%(B
\end{itemize}


\end{document}