Last active
December 17, 2015 13:58
-
-
Save knsh14/5620589 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- 基本5 コマンドを調べるためのコマンド | |
:info hoge | |
-- リスト6 リストの先頭にhogeを追加するコマンド | |
hoge : [] | |
-- 型1 出力の最後に結果の型を表示する | |
:set +t | |
-- 型5 有理数を使えるようにするコマンド | |
:m Data.Ratioという | |
-- 型6 追加機能を削除するコマンド | |
:unset +t | |
-- 型情報を表示するコマンド | |
:type hoge | |
-- 簡単なプログラム | |
WC.hs | |
-- 動かすには | |
runghc WC < quux.txt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- 問題 | |
-- 結果 | |
-- の順に書いていく | |
5 + 8 | |
-- 13 Integer | |
3 * 5 + 8 | |
-- 23 Integer | |
2 + 4 | |
-- 6 Integer | |
(+) 2 4 | |
-- 6 Integer | |
sqrt 16 | |
-- 4.0 double | |
succ 6 | |
-- 7 Integer | |
succ 7 | |
-- 8 Integer | |
pred 9 | |
-- 8 Integer | |
pred 8 | |
--7 Integer | |
sin(pi/2) | |
-- 1.0 Double | |
truncate pi | |
-- 3 Integer | |
round 3.5 | |
-- 4 Integer | |
round 3.4 | |
-- 3 Integer | |
floor 3.7 | |
-- 3 Integer | |
ceiling 3.3 | |
-- 4 Integer | |
-- 問題:ghciで,:?をタイプしていくつかのヘルプを表示する.let x = 1のようにして変数を定義し,:show bindingsと打つと何が起きるか | |
-- 解答:ヘルプ表示は省く.2つ目に関しては以下のようになった | |
-- it :: Integer = 3 | |
-- x :: Integer = 1 | |
-- 問題:words関数は文字列を単語に分解する関数である.これを利用してWC.hsをファイル内の単語を数えるようにする | |
--解答は以下のコード | |
main = interact wordcount | |
where wordcount input = show (length (words input)) ++ "\n" | |
-- 問題:WC.hsをさらに改造して,ファイル内の文字数を表示するようにする | |
-- 解答は以下のコード | |
main = interact wordcount | |
where wordcount input = show (length input) ++ "\n" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Teignmouth, England | |
Paris, France | |
Ulm, Germany | |
Auxerre, France | |
Brunswick, Germany | |
Beaumont-en-Auge, France | |
Ryazan, Russia |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- quux.txtを読み込むと行数を出力する | |
main = interact wordCount | |
where wordCount input = show (length (lines input)) ++ "\n" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment