The greatest weapons

Everything in Haskell has a Type Here are some Type declarations.

head :: [a] -> a – gets the first element of a list

tail :: [a] -> [a] – gets everything but the first element

last :: [a] -> a – gets the last element of a list

init :: [a] -> [a] – gets everything but the last element

(++) :: [a] -> [a] -> [a] – concatenates two lists together

(:) :: a -> [a] -> [a] – prepends an element to a list

fst :: (a,b) -> a – gets the first element of a tuple

snd :: (a,b) -> b – gets the second element of a tuple

(!!) :: [a]->Int a

数学中λ-calculus的表示法为：

1. λx.t
2. λx[t]

“λ”不具有任何特殊意思，标识着其表达式中的可取一数值x带入。 t是表达式（例如x+3、x^2+2x+1等）。

1. (λx.t)p
2. (λx[t])p

Lisp|scheme的λ表示法与数值代入：

(lambda (x) (+ x 1))
((lambda (x) (+ x 1) 10))


\x -> x+1
(\x -> x+1)10

Prelude> map (\x->x+1) [1..10]
[2,3,4,5,6,7,8,9,10,11]

\ para1 para2->(return value)
\ (para1,para2) -> (return value)


Lambda Calculus

基本的语法：Lambda Calculus的核心是表达式(Expression)，用FP语言写的程序执行的过程，本质上就是对表达式求值的过程

expression := variable | function | application funciton := λvariable.expression (.前面部分为定义(definition)，后面部分为函数体(body)) application := expression expression

<expr> ::= <identifier>
<expr> ::= lambda <identifier-list>. <expr>
<expr> ::= (<expr> <expr>)


变量的bound与free:

λx.xy →x is bound, y is free

表达式化简（Reduction)的基本法则:

α−reduction: λx.E→λy.E[y/x]
β−reduction:((λx.E)z)→E[z/x]
η−reduction(if x is not free in E): λx.(Ex)→E

• Alpha转换公理：例如，“lambda x y. x + y”转换为“lambda a b. a + b”。换句话说，函数的参数起什么名字没有关系，可以随意替换，只要函数体里面对参数的使用的地方也同时注意相应替换掉就是了。

• Beta转换公理：例如，“(lambda x y. x + y) 2 3”转换为“2 + 3”。这个就更简单了，也就是说，当把一个lambda函数用到参数身上时，只需用实际的参数来替换掉其函数体中的相应变量即可。

变量替换

[y/x]E → substitute all occurrences of x in E to y

Prelude> :type take
take :: Int -> [a] -> [a]
Prelude> let takeFive = take 5
Prelude> :type takeFive
takeFive :: [a] -> [a]
Prelude> takeFive [1..]
[1,2,3,4,5]


令狐冲
Engineer of offshore wind turbine technique research

My research interests include distributed energy, wind turbine power generation technique , Computational fluid dynamic and programmable matter.