Copyright c 2008 Zhenjiang Hu, All Right Reserved.

Similar documents
Copyright c 2006 Zhenjiang Hu, All Right Reserved.

3 3.1 algebraic datatype data k = 1 1,1... 1,n1 2 2,1... 2,n2... m m,1... m,nm 1 m m m,1,..., m,nm m 1, 2,..., k 1 data Foo x y = Alice x [y] B

haskell.gby

Functional Programming

ML Edinburgh LCF ML Curry-Howard ML ( ) ( ) ( ) ( ) 1

第9回 型とクラス

2

fp.gby

org/ghc/ Windows Linux RPM 3.2 GHCi GHC gcc javac ghc GHCi(ghci) GHCi Prelude> GHCi :load file :l file :also file :a file :reload :r :type expr :t exp

test.gby

# let rec sigma (f, n) = # if n = 0 then 0 else f n + sigma (f, n-1);; val sigma : (int -> int) * int -> int = <fun> sigma f n ( : * -> * ) sqsum cbsu


Parametric Polymorphism

Ⅴ 古陶器にみる装飾技法

連載 構文解析器結合子 山下伸夫 (( 株 ) タイムインターメディア ) 文字列の分解 1 1 Haskell lines Prelude lines :: String -> [String] lines "" = [] lines s = let (l,s'

monad.gby

相続支払い対策ポイント

150423HC相続資産圧縮対策のポイント

ハピタス のコピー.pages

Copyright 2008 All Rights Reserved 2

K227 Java 2

Jacques Garrigue

Java演習(4) -- 変数と型 --

プログラミングD - Java

(Basic Theory of Information Processing) Fortran Fortan Fortan Fortan 1

新・明解Java入門

# let st1 = {name = "Taro Yamada"; id = };; val st1 : student = {name="taro Yamada"; id=123456} { 1 = 1 ;...; n = n } # let string_of_student {n

Copyright 2010 Funai Consulting Co.,ltd. All right reserved. 1

VDM-SL VDM VDM-SL Toolbox VDM++ Toolbox 1 VDM-SL VDM++ Web bool

第12回 モナドパーサ

初心者にもできるアメブロカスタマイズ新2016.pages

- 2 Copyright (C) All Rights Reserved.

Copyright 2006 KDDI Corporation. All Rights Reserved page1

10/ / /30 3. ( ) 11/ 6 4. UNIX + C socket 11/13 5. ( ) C 11/20 6. http, CGI Perl 11/27 7. ( ) Perl 12/ 4 8. Windows Winsock 12/11 9. JAV

解きながら学ぶC++入門編

bdd.gby

Copyright All Rights Reserved. -2 -!

jssst-ocaml.mgp

koba/class/soft-kiso/ 1 λ if λx.λy.y false 0 λ typed λ-calculus λ λ 1.1 λ λ, syntax τ (types) ::= b τ 1 τ 2 τ 1

IPA:セキュアなインターネットサーバー構築に関する調査

8 if switch for while do while 2

Microsoft Word - 最終版 バックせどりismマニュアル .docx

10

void hash1_init(int *array) int i; for (i = 0; i < HASHSIZE; i++) array[i] = EMPTY; /* i EMPTY */ void hash1_insert(int *array, int n) if (n < 0 n >=

keysql42_usersguide

class IntCell { private int value ; int getvalue() {return value; private IntCell next; IntCell next() {return next; IntCell(int value) {this.value =

解きながら学ぶJava入門編

3 Java 3.1 Hello World! Hello World public class HelloWorld { public static void main(string[] args) { System.out.println("Hello World");

ML λ λ 1 λ 1.1 λ λ λ e (λ ) ::= x ( ) λx.e (λ ) e 1 e 2 ( ) ML λx.e Objective Caml fun x -> e x e let 1

My関数の作成演習問題集

超初心者用

Java updated

橡点検記録(集約).PDF

211 ‚æ2fiúŒÚ

プログラミングD - Java

untitled

ex01.dvi

, , B 305, ,

class IntCell { private int value ; int getvalue() {return value; private IntCell next; IntCell next() {return next; IntCell(int value) {this.value =

Condition DAQ condition condition 2 3 XML key value

10/ / /30 3. ( ) 11/ 6 4. UNIX + C socket 11/13 5. ( ) C 11/20 6. http, CGI Perl 11/27 7. ( ) Perl 12/ 4 8. Windows Winsock 12/11 9. JAV

CGI開発支援解説

パズルをSugar制約ソルバーで解く

64bit SSE2 SSE2 FPU Visual C++ 64bit Inline Assembler 4 FPU SSE2 4.1 FPU Control Word FPU 16bit R R R IC RC(2) PC(2) R R PM UM OM ZM DM IM R: reserved

piyo rtfd

C¥×¥í¥°¥é¥ß¥ó¥° ÆþÌç

2

リバースマップ原稿2

健康保険組合のあゆみ_top

Pascal Pascal Free Pascal CPad for Pascal Microsoft Windows OS Pascal

いま本文ー校了データ0822.indd

2

5 IO Haskell return (>>=) Haskell Haskell Haskell 5.1 Util Util (Util: Tiny Imperative Language) 1 UtilErr, UtilST, UtilCont, Haskell C


presen.gby

16soukatsu_p1_40.ai

2 2 ( M2) ( )


1 # include < stdio.h> 2 # include < string.h> 3 4 int main (){ 5 char str [222]; 6 scanf ("%s", str ); 7 int n= strlen ( str ); 8 for ( int i=n -2; i

xl 1 program Othello6; 2 {$APPTYPE CONSOLE} 3 uses SysUtils; 4 5 type 6 TMasuNo = 0..99; // 7 TYouso = (Soto,Kara,Kuro,Siro); // 8 TBan = array [TMasu

untitled

syspro-0405.ppt

Q&A集

コンピュータ概論

Java Java Java Java Java 4 p * *** ***** *** * Unix p a,b,c,d 100,200,250,500 a*b = a*b+c = a*b+c*d = (a+b)*(c+d) = 225

Java講座

ex01.dvi

r1.dvi

PowerPoint プレゼンテーション

tuat1.dvi

ohp03.dvi

6-1

MBLAS¤ÈMLAPACK; ¿ÇÜĹÀºÅÙÈǤÎBLAS/LAPACK¤ÎºîÀ®

第10回 モジュール

やよいの顧客管理

弥生給与/やよいの給与計算

弥生 シリーズ

弥生会計 プロフェッショナル/スタンダード/やよいの青色申告

弥生会計/やよいの青色申告

弥生会計 ネットワーク/プロフェッショナル2ユーザー

Transcription:

2008 10 27 Copyright c 2008 Zhenjiang Hu, All Right Reserved.

(Bool) True False data Bool = False True

Remark: not :: Bool Bool not False = True not True = False (Pattern matching) (Rewriting rules) not =

( ),( ) :: Bool Bool Bool False x True x = False = x False x True x = x = True Remark: False = False = False True = Haskell &&,

( ) :: Bool Bool Bool False False = False False True = False True True = True True False = False Remark: False = False = True =

Remark: (==) :: Bool Bool Bool x == y = (x y) (not x not y) ( ) :: Bool Bool Bool x y = not (x == y) Haskell /=

class/instance class Eq α where (==),( ) :: α α Bool x y = not (x == y) instance Eq Bool where x == y = (x y) (not x not y)

class Eq α Ord α where (<),( ),(>),( ) :: α α Bool x y = (x < y) (x == y) x > y = not (x y) x y = (x > y) (x == y) instance Ord Bool where False < False = False False < True = True True < False = False True < True = False

xor imply xor :: Bool Bool Bool xor p q = (p not q) (not p q) imply :: Bool Bool Bool imply p q = not p q leap: leap :: Int Bool leap y = y mod 4 == 0 imply (y mod 100 == 0) (y mod 400 == 0)

(0, 1, 2,...) Remark: data Nat = Zero Succ Nat Nat Zero, Succ Zero, Succ Zero, Succ (Succ Zero)

(+) :: Nat Nat Nat m + Zero = m m + (Succ n) = Succ (m + n) Zero + Succ (Succ Zero)

( ) :: Nat Nat Nat m Zero = Zero m (Succ n) = (m n) + m ( ) :: Nat Nat Nat m Zero = Succ Zero m Succ n = (m n) m

instance Eq Nat where Zero == Zero = True Zero == Succ n = False Succ m == Zero = False Succ m == Succ n = m == n instance Ord Nat where Zero < Zero = False Zero < Succ n = True Succ m < Zero = False Succ m < Succ n = m < n

data Nat = Zero Succ Nat deriving (Eq,Ord)

( ) :: Nat Nat Nat m Zero = m (Succ m) (Succ n) = m n Succ Zero Succ (Succ Zero) = { second equation for (-) } Zero Succ Zero = { case exhaustion }

fact :: Nat Nat fact Zero = Succ Zero fact (Succ n) = Succ n fact n Fibonacchi fib :: Nat Nat fib Zero = Zero fib (Succ Zero) = Succ Zero fib (Succ (Succ n)) = fib (Succ n) + fib n

Char ASCII (American Standard Code for Information Interchange)

ord :: Char Int: ASCII ord b 98 chr :: Int Char: ASCII chr 98 b instance Eq Char where x == y = ord x == ord y instance Ord Char where x < y = ord x < ord y

isdigit: isdigit :: Char Bool isdigit x = 0 x x 9 capitalise: captalise :: Char Char capitalise x islower x = chr(offset + ord x) otherwise = x where offset = ord A ord a

captalise a = { definition and islower a = True } chr(offset + ord a ) = { definition of offset } chr(ord A ord a + ord a ) = { arithmetic } chr(ord A ) = { since chr(ord c) = c for all c } A

String {, hello, This is a string.,...} type String = [Char]? "a" "a"? "Hello World" "Hello World"? putstr "Hello World" Hello World

show :: a String: show 100 100 show True True show (show 100) \ 100\ + :: String String String: hello ++ ++ world helloworld

Int : single precision integer Integer : arbitrary precision integer + ( ) 2 + 3 5 ( ) 2 3 1 ( ) 2 3 6 / ( ) 3/2 1.5 ˆ ( ) 2ˆ3 8 div ( ) div 3 2 1 3 div 2 1 mod ( ) mod 5 3 2 5 mod 3 2

fact :: Integer Integer fact 0 = 1 fact (n + 1) = (n + 1) fact n sign :: Int Int sign n n > 0 = 1 n == 0 = 0 n < 0 = 1

Float : single precision floating-point numbers Double : arbitrary precision floating-point numbers + ( ) 2.3 + 3.3 5.6 ( ) 2.5 3 0.5 ( ) 2.5 2.5 6.25 / ( ) 3.2/2 1.6

abs abs :: Num a a a abs x = if x < 0 then x else x abs x x < 0 = x otherwise = x

Hugs