annotate haskell.html @ 0:c0be45e5b32f

Initial commit
author Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
date Fri, 05 Jul 2013 21:23:19 +0900
parents
children a69b147cd82e
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1 <!DOCTYPE html>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2 <!--
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
3 Google HTML5 slide template
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
4
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
5 Authors: Luke Mahé (code)
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
6 Marcin Wichary (code and design)
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
7
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
8 Dominic Mazzoni (browser compatibility)
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
9 Charles Chen (ChromeVox support)
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
10
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
11 URL: http://code.google.com/p/html5slides/
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
12 -->
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
13
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
14 <html>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
15 <head>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
16 <title>Haskell による Web Service 構築入門</title>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
17
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
18 <meta charset='utf-8'>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
19 <script
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
20 src='http://web.amothic.com/html5slides/slides.js'></script>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
21 </head>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
22
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
23 <style>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
24 /* Your individual styles here, or just use inline styles if that’s
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
25 what you want. */
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
26
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
27
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
28 </style>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
29
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
30 <body style='display: none'>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
31
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
32 <section class='slides layout-regular template-concurrency'>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
33
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
34 <article>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
35 <h1>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
36 Haskell による Web Service 構築入門
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
37 </h1>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
38 <p>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
39 Daichi TOMA
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
40 <br>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
41 Jul 6, 2013
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
42 </p>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
43 </article>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
44
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
45 <article>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
46 <h3>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
47 Haskell とは
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
48 </h3>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
49 <p>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
50 純粋関数型プログラミング言語
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
51 </p>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
52 <p>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
53 引数に関数を作用させて計算を行います。
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
54 </p>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
55 </article>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
56
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
57 <article>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
58 <h3>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
59 命令型プログラミングとの違い
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
60 </h3>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
61 <p>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
62 命令型プログラミング言語では、命令の並びをコンピュータに与えて、それを実行します。
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
63 </p>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
64 <p>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
65 関数型プログラミング言語では、何であるかという定義を与えます。
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
66 </p>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
67 <p>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
68 例:n番目のフィボナッチ数を求める関数の定義
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
69 <pre>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
70 fib 0 = 0
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
71 fib 1 = 1
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
72 fib n = fib (n - 1) + fib (n - 2)
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
73 </pre>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
74 </p>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
75 </article>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
76
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
77 <article>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
78 <h3>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
79 Haskell の特徴
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
80 </h3>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
81 <p>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
82 <ul>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
83 <li>副作用を持たない
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
84 </ul>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
85 </p>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
86 <p>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
87 関数は副作用を持ちません
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
88 </p>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
89 <p>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
90 関数にできることは、何かを計算して結果を返すことだけです。<br>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
91 関数は同じ引数で呼ばれた場合、同じ値を返すことを保証します。
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
92 </p>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
93 <p>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
94 関数の正しさを簡単に推察でき、正しいと分かっている関数同士を容易に組み合わせることができます。
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
95 </p>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
96 </article>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
97
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
98 <article>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
99 <h3>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
100 Haskell の特徴
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
101 </h3>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
102 <p>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
103 <ul>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
104 <li>遅延評価
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
105 </ul>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
106 </p>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
107 <p>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
108 Haskellは、結果が必要になるまで関数を評価しません。
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
109 </p>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
110 <p>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
111 遅延評価のため、無限の大きさのデータを扱うことが可能です。
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
112 </p>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
113 <p>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
114 例:奇数の無限のリストから最初の3つを入手する
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
115 <pre>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
116 take 3 [1,3..]
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
117 </pre>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
118 </p>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
119 </article>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
120
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
121 <article>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
122 <h3>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
123 Haskell の特徴
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
124 </h3>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
125 <p>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
126 <ul>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
127 <li>静的型付け
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
128 </ul>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
129 </p>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
130 <p>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
131 型規則に従ってない式が存在しないことを保証します。
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
132 </p>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
133 <p>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
134 また型推論を持つため、すべての式に明示的に型を書く必要はありません。
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
135 </p>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
136 <p>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
137 コンパイラが非常に多くのバグを見つけてくれるので、コンパイルが通れば概ね思い通りに動きます。
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
138 </p>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
139 </article>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
140
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
141 <article>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
142 <h3>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
143 よし、分かった。では Haskell を使う方法を教えてくれ。
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
144 </h3>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
145 <p>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
146 一番手っ取り早い方法は、Haskell Platformを導入することです。
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
147 </p>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
148 <p>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
149 Haskellのコンパイラで最も広く使われている The Glasgow Haskell Compiler (GHC) や、便利な Haskell のライブラリのセットが付いてきます!
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
150 </p>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
151 <p>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
152 <a href="http://www.haskell.org/platform/">http://www.haskell.org/platform/</a>にアクセスして、利用しているOS向けの指示に従ってください。
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
153 </p>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
154 </article>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
155
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
156 <article>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
157 <h3>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
158 ghciで遊んでみる
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
159 </h3>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
160 <p>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
161 <pre>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
162 ghci&gt; 2+3
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
163 5
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
164 ghci&gt; succ 3
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
165 4
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
166 ghci&gt; 2 &gt; 3
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
167 False
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
168 ghci&gt; True &amp;&amp; False
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
169 False
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
170 </pre>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
171 </p>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
172 </article>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
173
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
174 <article>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
175 <h3>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
176 ghciで遊んでみる
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
177 </h3>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
178 <p>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
179 gchi内で関数を定義する際はletが必要
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
180 <pre>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
181 ghci&gt; let doubleMe x = x + x
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
182 ghci&gt; doubleMe 4
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
183 8
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
184 ghci&gt; let doubleUs x y = doubleMe x + doubleMe y
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
185 ghci&gt; doubleUs 2 3
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
186 10
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
187 ghci&gt; doubleUs 1.2 4.5
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
188 11.4
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
189 </pre>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
190 </p>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
191 </article>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
192 <article>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
193 <h3>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
194 Haskell Platform をインストールしたら
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
195 </h3>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
196 <p>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
197 Terminal を開き、
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
198 <pre>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
199 $ ghci
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
200 </pre>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
201 とタイプすることで、対話モードが起動できます。
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
202 </p>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
203 <p>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
204 対話モードでは、実際に関数を呼び出して、結果を直接見ることができます。
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
205 </p>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
206 <p>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
207 対話モードを終了するには、
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
208 <pre>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
209 ghci&gt; :q
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
210 </pre>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
211 とタイプし、ENTERを押します。
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
212 </p>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
213 </article>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
214
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
215 <article>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
216 <h3>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
217 なぜ Haskell で Web Service を書くのか
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
218 </h3>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
219 </article>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
220
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
221 <article>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
222 <h3>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
223 Haskell の Web Framework
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
224 </h3>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
225 </article>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
226
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
227 <article>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
228 <h3>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
229 Warp
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
230 </h3>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
231 <p>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
232 軽量、高速 HTTP サーバです。
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
233 </p>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
234 <p>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
235 Haskell の軽量スレッドを活かして書かれています。
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
236 </p>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
237 <p>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
238 Pong benchmark (req/s)
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
239 <img class='centered' src='pic/pong.png'>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
240 </p>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
241 </article>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
242
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
243 <article>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
244 <h3>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
245 とりあえず、Warp 入れてみる
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
246 </h3>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
247 <pre>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
248 $ cabal install warp
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
249 </pre>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
250 </article>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
251
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
252 <article class="smaller">
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
253 <h3>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
254 簡単なプログラム
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
255 </h3>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
256 <pre>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
257 {-# LANGUAGE OverloadedStrings #-}
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
258 import Network.Wai
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
259 import Network.HTTP.Types (status200)
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
260 import Network.Wai.Handler.Warp (run)
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
261
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
262 application _ = return $
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
263 responseLBS status200 [("Content-Type", "text/plain")] "Hello World"
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
264
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
265 main = run 3000 application
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
266 </pre>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
267 <p>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
268 このソースコードを読み解いていきます。
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
269 </p>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
270 <p>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
271 Haskell は型を見れば多くのことが分かる言語です。<br>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
272 ということで、関数の型を見ていきます!
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
273 </p>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
274 </article>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
275
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
276 <article class="smaller">
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
277 <h3>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
278 関数の型を確認する
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
279 </h3>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
280 <p>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
281 まず、対話モードを開きます。
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
282 </p>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
283 <pre>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
284 $ ghci
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
285 </pre>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
286 <p>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
287 Wai 及び Warp の module を import します。<br>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
288 Wai というのは、Web Application Interface の略で、Web サーバと Web アプリケーション間の共通のプロトコルを取り扱います。
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
289 </p>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
290 <pre>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
291 ghci&gt; :module +Network.Wai
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
292 ghci&gt; :module +Network.Wai.Handler.Warp
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
293 </pre>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
294 <p>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
295 型を教えて貰うには、:t コマンドに続けて正しい式を入力します。
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
296 </p>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
297 <pre>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
298 ghci&gt; :t run
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
299 run :: Port -&gt; Application -&gt; IO ()
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
300 </pre>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
301 </article>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
302
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
303 <article class="smaller">
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
304 <h3>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
305 run
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
306 </h3>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
307 <pre>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
308 ghci&gt; :t run
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
309 run :: Port -&gt; Application -&gt; IO ()
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
310 </pre>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
311 <p>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
312 run は、Port と Application を受け取って、IO () を返す関数だということが分かります。
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
313 </p>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
314 <p>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
315 Port は、Int の別名です。<br>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
316 別名などの定義は、:t ではみれないので、:i を使うとよいでしょう。<br>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
317 Haskellでは、関数は小文字、型名などは大文字で始まります。
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
318 </p>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
319 </article>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
320 <article class="smaller">
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
321 <h3>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
322 Application は、なんでしょうか?
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
323 </h3>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
324 <pre>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
325 ghci&gt; :i Application
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
326 type Application =
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
327 Request -&gt; Control.Monad.Trans.Resource.ResourceT IO Response
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
328 </pre>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
329 <p>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
330 Monad に包まれていて少しわかりにくいですが、端的に言えば Request を受け取って Response を返す関数を表しています。
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
331 </p>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
332 <p>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
333 ResourceT は、リソースの解放を取り扱う Monad、 IO は、入出力を取り扱う Monad です。
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
334 </p>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
335 <p>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
336 Haskell では、関数が副作用を持つことは許されませんが、IO アクションによって IO 操作を処理系に押し付けています。
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
337 </p>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
338 </article>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
339
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
340 <article class="smaller">
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
341 <h3>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
342 runとは結局なんぞや
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
343 </h3>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
344 <pre>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
345 {-# LANGUAGE OverloadedStrings #-}
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
346 import Network.Wai
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
347 import Network.HTTP.Types (status200)
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
348 import Network.Wai.Handler.Warp (run)
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
349
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
350 application _ = return $
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
351 responseLBS status200 [("Content-Type", "text/plain")] "Hello World"
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
352
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
353 main = run 3000 application
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
354 </pre>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
355 <p>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
356 型情報を読むことでおおよそ分かったような気がしませんか!
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
357 </p>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
358 <p>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
359 Port 番号と、Request を受け取って Response 返す関数を受け取る<br>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
360 run は IO () を返すので、外界に影響を与える
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
361 </p>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
362 <p>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
363 実際の動作としては、この関数 run は受け取った Port 番号で、Application を実行します。
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
364 </p>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
365 <p>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
366 次に、Application の実装を見ていきます。
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
367 </p>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
368 </article>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
369
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
370 <article class="smaller">
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
371 <h3>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
372 Hello Worldと出力する簡単なお仕事
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
373 </h3>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
374 <pre>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
375 application _ = return $
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
376 responseLBS status200 [("Content-Type", "text/plain")] "Hello World"
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
377 </pre>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
378 <p>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
379 まず引数で渡される Request は _ (Underscore) となっているので、使用していません。
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
380 </p>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
381 </article>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
382
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
383 <article class="smaller">
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
384 <h3>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
385 responseLBS とは?
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
386 </h3>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
387 <pre>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
388 Prelude Network.Wai.Handler.Warp Network.Wai Network.HTTP.Types&gt; :t responseLBS
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
389 responseLBS
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
390 :: Status
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
391 -&gt; ResponseHeaders
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
392 -&gt; Data.ByteString.Lazy.Internal.ByteString
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
393 -&gt; Response
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
394 </pre>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
395 <p>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
396 Statusと、ResponseHeaders、ByteStringを受け取り、Responseを返します。
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
397 </p>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
398 <p>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
399 簡単に説明すると、文字列からResponseを構築するためのコンストラクターです。
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
400 </p>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
401 <p>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
402 ByteStringは、Stringと比較して効率よく文字列を扱います。
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
403 プログラムの最初に書かれている OverloadedStrings という言語拡張は、ダブルクオートで囲んだ文字列を、ByteString リテラルとして扱ってくれます。
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
404 </p>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
405 <pre>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
406 {-# LANGUAGE OverloadedStrings #-}
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
407 </pre>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
408 </article>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
409
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
410 <article class="smaller">
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
411 <h3>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
412 Hello.hs
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
413 </h3>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
414 <pre>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
415 {-# LANGUAGE OverloadedStrings #-}
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
416 import Network.Wai
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
417 import Network.HTTP.Types (status200)
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
418 import Network.Wai.Handler.Warp (run)
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
419
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
420 application _ = return $
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
421 responseLBS status200 [("Content-Type", "text/plain")] "Hello World"
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
422
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
423 main = run 3000 application
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
424 </pre>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
425 </article>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
426
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
427 <article>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
428 <h3>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
429 おおよその内容は掴めた、では実行してみようではないか。
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
430 </h3>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
431 <p>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
432 実行方法は2つあります。
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
433 </p>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
434 <p>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
435 <ul>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
436 <li>コンパイルせずに実行
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
437 </ul>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
438 <pre>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
439 $ runghc Hello.hs
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
440 </pre>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
441 </p>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
442 <p>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
443 <ul>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
444 <li>コンパイルして実行
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
445 </ul>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
446 <pre>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
447 $ ghc --make Hello.hs
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
448 $ ./Hello
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
449 </pre>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
450 </p>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
451 </article>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
452 <article>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
453 <h3>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
454 サイトにアクセスしてみる
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
455 </h3>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
456 <p>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
457 <a href="http://localhost:3000/">http://localhost:3000/</a>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
458 </p>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
459 <p>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
460 Hello Worldと表示されれば成功です。
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
461 </p>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
462 </article>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
463
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
464 <article>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
465 <h3>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
466 さすがにこれは簡単すぎる…
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
467 </h3>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
468 <p>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
469 こんなの30秒で書けるよという皆様のために、次に単純な Routing っぽいものを実装してみたいと思います。
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
470 </p>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
471 <p>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
472 Application が受け取る Request には、様々な情報が含まれています。<br>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
473 その中には pathInfo という、どこの path へアクセスしてきたかの情報があります。
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
474 </p>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
475 </article>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
476
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
477 <article>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
478 <h3>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
479 pathInfoの情報をどう入手するか
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
480 </h3>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
481 <p>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
482 実は超簡単です。
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
483 </p>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
484 <pre>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
485 pathInfo request
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
486 </pre>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
487 <p>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
488 pathInfo という関数に Request を渡すだけ!
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
489 </p>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
490 <p>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
491 Haskell では、レコード構文というデータ型のフィールドにアクセスするためのコードを自動生成する仕組みがあります。
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
492 レコード構文で、データ型を定義するとデータ型が作られるのと同時に、フィールド名でフィールドを取得する関数たちが自動で作られます。
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
493 </p>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
494 <p>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
495 <pre>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
496 ghci&gt; :t pathInfo
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
497 pathInfo :: Request -&gt; [Data.Text.Internal.Text]
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
498 </pre>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
499 </p>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
500 </article>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
501
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
502 <article>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
503 <h3>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
504 pathによって返す関数を変えてみよう
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
505 </h3>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
506 <p>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
507 まず、application で request を取り routes という関数に path を渡すように変更します。
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
508 </p>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
509 <pre>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
510 application request = return $
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
511 routes $ pathInfo request
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
512 </pre>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
513 <p>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
514 routes は、path を受け取って response を返す関数です。
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
515 </p>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
516 <pre>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
517 routes path = findRoute path routeSetting
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
518 </pre>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
519 <p>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
520 routes では、routeSetting という List から path が一致するもの探します。
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
521 </p>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
522 </article>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
523
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
524 <article>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
525 <h3>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
526 pathによって返す関数を変えてみよう
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
527 </h3>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
528 <p>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
529 findRoute では、再帰的に List を探索しています。<br>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
530 一致するものがなければ、notFound という関数を返します。<br>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
531 一致するものがあれば、routeSetting に記載された関数を返します。
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
532 <pre>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
533 findRoute path [] = notFound
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
534 findRoute path ((p,f):xs)
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
535 | path == p = f
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
536 | otherwise = findRoute path xs
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
537
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
538 routeSetting = [([], index),
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
539 (["hello"], hello),
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
540 (["welcome","world"],world)]
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
541 </pre>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
542 </article>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
543
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
544 <article class="smaller">
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
545 <h3>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
546 response関数を定義しよう
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
547 </h3>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
548 <p>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
549 いくつか定義してみます。
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
550 </p>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
551 <pre>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
552 notFound = do
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
553 responseLBS status404 [("Content-type", "text/html")] $ "404 - File Not Found"
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
554
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
555 index = do
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
556 responseLBS status200 [("Content-type", "text/html")] $ "index page"
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
557
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
558 hello = do
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
559 responseLBS status200 [("Content-type", "text/html")] $ "hello, my name is Tom"
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
560
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
561 world = do
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
562 responseLBS status200 [("Content-type", "text/html")] $ "Welcome to Underground"
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
563 </pre>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
564 </article>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
565
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
566 <article class="smaller">
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
567 <h3>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
568 完成!
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
569 </h3>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
570 <p>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
571 <a href="https://gist.github.com/amothic/5933808">Source Code</a>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
572 <pre>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
573 application request = return $
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
574 routes $ pathInfo request
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
575
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
576 routes path = findRoute path routeSetting
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
577
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
578 findRoute path [] = notFound
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
579 findRoute path ((p,f):xs)
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
580 | path == p = f
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
581 | otherwise = findRoute path xs
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
582 routeSetting = [([], index),
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
583 (["hello"], hello),
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
584 (["welcome","world"],world)]
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
585 notFound = do
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
586 responseLBS status404 [("Content-type", "text/html")] $ "404 - File Not Found"
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
587 index = do
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
588 responseLBS status200 [("Content-type", "text/html")] $ "index page"
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
589 hello = do
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
590 responseLBS status200 [("Content-type", "text/html")] $ "hello, my name is Tom"
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
591 world = do
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
592 responseLBS status200 [("Content-type", "text/html")] $ "Welcome to Underground"
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
593
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
594 main = run 3000 application
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
595 </pre>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
596 </p>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
597 </article>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
598
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
599 <article>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
600 <h3>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
601 実際に動かしてみる!
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
602 </h3>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
603 <p>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
604 シンプルなシステムですが、実際に動くのか確かめてみます。
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
605 </p>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
606 <p>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
607 "index page" と表示されるはず<br>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
608 <a href="http://localhost:3000/">http://localhost:3000/</a>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
609 </p>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
610 <p>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
611 "hello, my name is Tom" と表示されるはず<br>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
612 <a href="http://localhost:3000/hello">http://localhost:3000/hello</a>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
613 </p>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
614 <p>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
615 "welcome to Underground" と表示されるはず<br>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
616 <a href="http://localhost:3000/welcome/world">http://localhost:3000/welcome/world</a>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
617 </p>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
618 <p>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
619 一致するpathがないので、"404 - File Not Found" と表示されるはず<br>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
620 <a href="http://localhost:3000/hogehoge">http://localhost:3000/hogehoge</a>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
621 </p>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
622 </article>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
623 <article>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
624 <h3>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
625 そして気づくことなど
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
626 </h3>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
627 <p>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
628 あれ、Haskellのプログラムって短くね?
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
629 </p>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
630 <p>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
631 そうです、圧倒的な記述力も特徴なんです。
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
632 </p>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
633 <p>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
634 速くて安全なHaskellで、あなたもWeb Serviceを作って見ませんか?
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
635 </p>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
636 </article>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
637
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
638 <article>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
639 <h3>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
640 参考文献
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
641 </h3>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
642 <p>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
643 <ul>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
644 <li>田中 英行, 村主 崇行(2012) 『すごいHaskellたのしく学ぼう!』 オーム社
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
645 <li><a href="http://mew.org/~kazu/material/2011-ll-haskell.pdf">メタプログラミングの光と闇 ~ Haskell 編~</a>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
646 <li><a href="http://www.yesodweb.com/blog/2011/03/preliminary-warp-cross-language-benchmarks">Preliminary Warp Cross-Language Benchmarks</a>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
647 <li><a href="http://yannesposito.com/Scratch/en/blog/Yesod-tutorial-for-newbies/">YBlog - Haskell web programming</a>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
648 </ul>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
649 </p>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
650 </article>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
651 </section>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
652 </body>
c0be45e5b32f Initial commit
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
653 </html>