#### 冒泡排序


sort1 [x] = [x]
sort1 (x:x1:xs)  {-选取了一个x1temp 值  x当做首数，x1:temp-}
| x>x1 = x1:sort1 (x:xs)
| otherwise = x:sort1 (x1:xs)
mpsort [] = []
mpsort x = let tmp = sort1 x in
mpsort (init tmp) ++ [(last tmp)]


#### 直接排序

import Data.List
selectsort::[Int] -> [Int]
selectsort [] = []
selectsort [x] = [x]
selectsort xs = minimum xs : selectsort ( delete ( minimum xs )  xs)



#### 快速排序1


quicksort :: (Ord a) => [a] -> [a]
quicksort [] = []
quicksort (x:xs) =
let smallerSorted = quicksort [a | a <- xs, a <= x]
biggerSorted = quicksort [a | a <- xs, a > x]
in smallerSorted ++ [x] ++ biggerSorted


#### 快速排序2

quicksort :: (Ord a) => [a] -> [a]
quicksort [] = []
quicksort (x:xs) =
let smallerSorted = quicksort (filter (<=x) xs)
biggerSorted = quicksort (filter (>x) xs)
in  smallerSorted ++ [x] ++ biggerSorted


### 如果别人问你:: => ->是什么意思？

(==) :: Eq a => a -> a -> Bool 可以这样阅读： 相当函数的两个相同的类型值作为参数并返回一个bool值，而这两个参数的类型同在Eq类之中(即类型约束） eq这一类型 提供了判断相等性的接口，凡是可以比较相等性的类型嗯必属于Eq类 （=>左边的部分叫做类型约束） a表示人意的类型 ———泛形 —多态函数挂钩。。。。

:: 读作他的类型为 （类似 !! 从list去除 第几个元素 <- 属于 elem是什么的元素 mod 可以和什么除。。

maximum' :: (Ord a) => [a] -> a
maximum' [] = error "maximum of empty list"
maximum' [x] = x
maximum' (x:xs)
| x > maxTail = x
| otherwise = maxTail
where maxTail = maximum' xs


### 如果别人叫你简化上面的maximum程序

maximum' :: (Ord a) => [a] -> a
maximum' [] = error "maximum of empty list"
maximum' [x] = x
maximum' (x:xs) = max x (maximum' xs)


### 如果有人问你replicate 3 5是如何实现的？

replicate' :: (Num i, Ord i) => i -> a -> [a]
replicate' n x
| n <= 0    = []
| otherwise = x:replicate' (n-1) x


### 如果有人问你take是如何实现的呢？ drop?

take' :: (Num i, Ord i) => i -> [a] -> [a]
take' n _
| n <= 0   = []
take' _ []     = []
take' n (x:xs) = x : take' (n-1) xs


_ 代表任意东西

### 如果有人问你reverse如何实现？

reverse' :: [a] -> [a]
reverse' [] = []
reverse' (x:xs) = reverse' xs ++ [x]


### 如果有人问你repeat如何实现？

repeat' :: a -> [a]
repeat' x = x:repeat' x


### 如果有人做了一个tuple ，想要用zip产生更多tuples？

zip' :: [a] -> [b] -> [(a,b)]
zip' _ [] = []
zip' [] _ = []
zip' (x:xs) (y:ys) = (x,y):zip' xs ys


### 如果有人问你mod的类似函数 elem的实现？

elem' :: (Eq a) => a -> [a] -> Bool
elem' a [] = False
elem' a (x:xs)
| a == x    = True
| otherwise = a elem' xs


### 如果有人问你typeclass有哪里类？

scheme版的lambda:

    (lambda (x y)
(+ x y))


    (\y -> y + 3）
其中\后面跟着参数  ->后面跟着函数体


map (\y-> y+3) [3,5,6]


### 19.如果有人问你flip有什么含义？

let f x  y = x / y
Prelude> map (f 2) [1,2,3]
[2.0,1.0,0.6666666666666666]
Prelude> map (flip f 2) [1,2,3]
[0.5,1.0,1.5]


### 20. 如何有人问 如何运行 2048

\$ runhaskell putchar_test.hs
use runhaskell to run the *.hs programme


quicksort (x:xs) =
elem' a (x:xs)

zip' (x:xs) (y:ys) = (x,y):zip' xs ys
reverse' (x:xs) = reverse' xs ++ [x]

take' n (x:xs) = x : take' (n-1) xs
maximum' (x:xs) = max x (maximum' xs)
maximum' (x:xs)


### 22. 如果有人问如何写出阶乘形式？

factorial :: (Integral a) => a -> a
factorial 0 = 1
factorial n = n * factorial (n - 1)


### 26. 如果别人问你 | 有什么意义？

bmiTell :: (RealFloat a) => a -> a -> String
bmiTell weight height
| weight / height ^ 2 <= 18.5 = "You're underweight, you emo, you!"
| weight / height ^ 2 <= 25.0 = "You're supposedly normal. Pffft, I bet you're ugly!"
| weight / height ^ 2 <= 30.0 = "You're fat! Lose some weight, fatty!"
| otherwise                   = "You're a whale, congratulations!"



lucky :: (Integral a) => a -> String
lucky 7 = "LUCKY NUMBER SEVEN!"
lucky x = "Sorry, you're out of luck, pal!"



sayme函数:

sayMe :: (Integral a) => a -> String
sayMe 1 = "One!"
sayMe 2 = "Two!"
sayMe 3 = "Three!"
sayMe 4 = "Four!"
sayMe 5 = "Five!"
sayMe x = "Not between 1 and 5"


### 27. 如果别人叫你简化bmiTell函数

bmiTell :: (RealFloat a) => a -> a -> String
bmiTell weight height
| bmi <= 18.5 = "You're underweight, you emo, you!"
| bmi <= 25.0 = "You're supposedly normal. Pffft, I bet you're ugly!"
| bmi <= 30.0 = "You're fat! Lose some weight, fatty!"
| otherwise   = "You're a whale, congratulations!"
where bmi = weight / height ^ 2


### 28. 如果别人问你 where可以跟多少个变量 ？

bmiTell :: (RealFloat a) => a -> a -> String
bmiTell weight height
| bmi <= skinny = "You're underweight, you emo, you!"
| bmi <= normal = "You're supposedly normal. Pffft, I bet you're ugly!"
| bmi <= fat    = "You're fat! Lose some weight, fatty!"
| otherwise     = "You're a whale, congratulations!"
where bmi = weight / height ^ 2
skinny = 18.5
normal = 25.0
fat = 30.0


### 29. 如果有人问你 where当中可以使用模式匹配吗？

where bmi = weight / height ^ 2
(skinny, normal, fat) = (18.5, 25.0, 30.0)



### 30. 如果别人叫你写一个show类型的函数？

tell :: (Show a) => [a] -> String
tell [] = "The list is empty"
tell (x:[]) = "The list has one element: " ++ show x
tell (x:y:[]) = "The list has two elements: " ++ show x ++ " and " ++ show y
tell (x:y:_) = "This list is long. The first two elements are: " ++ show x ++ " and " ++ show y


### 31. 如果别人问你Int 和Integer的区别？

Int 有上下线 Integer没有

Prelude> minBound :: Int
-9223372036854775808
Prelude> min
min       minBound  minimum
Prelude> minBound  :: Integer

<interactive>:247:1:
No instance for (Bounded Integer) arising from a use of minBound'



### 32. 如果别人问你char and [char] 的区别？

Prelude> :t 'a'
'a' :: Char
Prelude> :t "a"
"a" :: [Char]
Prelude> :t "dfasdf"
"dfasdf" :: [Char]
Prelude>


### 33. 如果别人问你变量有类型，那么函数是不是也有类型？

removeNonUppercase :: [Char] -> [Char]
removeNonUppercase st = [ c | c <- st, c elem ['A'..'Z']]


removeNonUppercase 的类型为 [Char]->[Char]，从它的参数和回传值的类型上可以看出， 它将一个字串映射为另一个字串。[Char] 与 String 是等价的，但使用 String 会更清晰： removeNonUppercase :: String -> String。编译器会自动检测出它的类型，我们还是标明了 它的类型声明。要是多个参数的函数该怎样？如下便是一个将三个整数相加的简单函数 参数之间由 -> 分隔，而与回传值之间并无特殊差异

### 35. 如果别人问你高阶函数是如何定义？

map f lst --将lst按照函数f映射得到一个新的数列
map :: (a->b) -> [a] ->
map f [] = []
map f (x:xs) = f x : map f xs



### 36. 如果别人问你如何使用 :brower 提供的函数类型？

36.1
Prelude> :t product
product :: Num a => [a] -> a
Prelude> product [3,5,2]
30
36.2
readFile :: FilePath -> IO String

"fdsf"
Prelude> d
"fdsf"



### 37. 如果别人问你如何切断一个数组在某个位置？

splitAt :: Int -> [a] -> ([a], [a])
Prelude> splitAt 3 [3,5,6,2,3,6,3]
([3,5,6],[2,3,6,3])



### 38. 如果别人问你为什么你这样使用subtract?

subtract :: Num a => a -> a -> a
Prelude> subtract 20 3
-17
Prelude> subtract [30,3] [3,3]


### 39. 如果别人问你 zip相关的函数？

    Prelude> unzip [(3,4)]
([3],[4])
Prelude> unzip [(3,4),(3,7)]
([3,3],[4,7])
Prelude> unzip [(3,4),(3,7),(7,4)]
([3,3,7],[4,7,4])
Prelude> unzip [(3,4),(3,7),(7,4),(8,9)]
([3,3,7,8],[4,7,4,9])
Prelude> unzip [((3,4),(3,7)),((7,4),(8,9))]
([(3,4),(7,4)],[(3,7),(8,9)])

unzip3 :: [(a, b, c)] -> ([a], [b], [c])

Prelude> unzip3 [(3,6,3)]
([3],[6],[3])
Prelude> unzip3 [(3,6,3),(3,5,9)]
([3,3],[6,5],[3,9])
Prelude> unzip3 [(3,6,3),(3,5,9),(8,9,0)]
([3,3,8],[6,5,9],[3,9,0])
Prelude> unzip3 [(3,6,3,5),(3,5,9,3),(8,9,0,6)]

<interactive>:172:9:
Couldn't match expected type (a0, b0, c0)'
with actual type (t0, t1, t2, t3)'



### 40. 如果别人问你un相关的函数？

Prelude> unlines ["ds","dfsf"]
"ds\ndfsf\n"
until :: (a -> Bool) -> (a -> a) -> a -> a
unwords :: [String] -> String
Prelude> unwords ["dsf","fdsf"]
"dsf fdsf"


### 41. 如果比人问你如何使用 sin等三角函数？

Prelude> sin (45/180*pi)
0.7071067811865475
Prelude> sin (45*pi/180)
0.7071067811865475



   isAscii, isLatin1, isControl, isPrint, isSpace, isUpper, isLower,
isAlpha, isDigit, isOctDigit, isHexDigit, isAlphaNum,
digitToInt, intToDigit,
toUpper, toLower,
ord, chr,等



ord将字母转换为数字, chr反之.

### 43.3 描述法

Prelude>  let nouns = ["he","she","I"]
["lazy he","lazy she","lazy I","handsome he","handsome she","handsome I","something he","something she","something I"]

*Main> let nouns = ["he","she","I"]
["lazy he","lazy she","lazy I","handsome he","handsome she","handsome I","something he","something she","something I"]


Prelude>  let triangels=[(a,b,c)|c<-[1..10],b<-[1..c],a<-[1..b],c^2==a^2+b^2,a+b+c==24]
Prelude> triangels
[(6,8,10)]



scilab 的atoms python的 easy_install 或者pip redhat 的yum

### 47. 如果别人问你有几个基本的TypeClass?

#### 47.7 Num

Num 是表示数字的 Typeclass，它的成员类型都具有数字的特征。检查一个数字的类型：

#### 47.9 Floating

let triangels=[(a,b,c)|c<-[1..10],b<-[1..10],a<-[1..10]]
let righttriangels=[(a,b,c)|c<-[1..10],b<-[1..c],a<-[1..b],a^2+b^2==c^2]
let righttriangelsc=[(a,b,c)|c<-[1..10],b<-[1..c],a<-[1..b],a^2+b^2==c^2,a+b+c==24]



#### 49. 如果别人问你如何表示数学的集合？

Prelude> [x*2|x <- [1..10]]
[2,4,6,8,10,12,14,16,18,20]
Prelude> [x*2|x<- [1..10],x*2 >=12 ]
[12,14,16,18,20]
Prelude> [x | x <- [50..100], x mod 7 ==3]
[52,59,66,73,80,87,94]



#### 50. 如果别人问你!! 代表什么东西？

[3, 5,6] !!2
*Main> [3, 5,6] !!2
6


#### 51. 几个常用的数组提取函数？

*Main> head [5,6,4]
5
*Main> last [5,6,4]
4
*Main> tail [5,6,4]
[6,4]
*Main> init [5,6,6,43,6]
[5,6,6,43]



length null reverse take等函数 具体说一下take

*Main> take 4 [5,6,7,4,3,8]
[5,6,7,4]
*Main> take 3 [5,6,7,4,3,8]
[5,6,7]
*Main> take 2 [5,6,7,4,3,8]
[5,6]
*Main>
`

##### 令狐冲
###### Engineer of offshore wind turbine technique research

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