您的位置:首页 > 其它

haskell笔记1

2018-01-31 16:11 225 查看

1 .function_name

functions can’t begin with uppercase letters

2 . how to unload a module

type in :m

:m


3 . name(definition)

When a function doesn’t take any parameters, we usually say it’s a definition (or a name). Because we can’t change what names (and functions) mean once we’ve defined them

4 .list

1.list is homogenous(同质的)

2.putting two lists together

//1:this method only takes two lists!
//2:will walk through the whole two lists,if add two very //long lists together,it will cost a lot of time
[1,2,3,4]++[2,3,4,5]
>>[1,2,3,4,2,3,4,5]
[1,2,3,4]++[5]
>>[1,2,3,4,5]
//[1,2,3,4]++5 is wrong


//1:can add a element at the beginning of a list(noted: //only a element)
//2:only takes a element and a list
2:[1,2,3,4]
>>[2,1,2,3,4]
//[2]:[1,2,3] is wrong


3 .find a element by index

//find a element  by index
[1,2,3,4]!!3
>>4
"black"!!2
>>a


4.head tail init last用法



5 . make a list

[1,2..20]
[2,4,6..20]
[0.1,0.3,0.5..1]
\\精度问题


6 .list comprihension

//集合说明方式

[x*2|x<-[1,2..10]]
[x*2|x<-[1,2..10],x*2>12]


5 tuples

difference between list and tuple

1.1 tuple is not homogenous(同质的)

1.2 tuple must be specified the number of values when it is created

some function used on pair

fst (1,2)
>> 1
snd (2,3)
>> 3
zip [1,2,3] [2,3,4]
>> [(1,2),(2,3),(3,4)]
//zip two lists into a pairs


6 note about difference between haskell and common language like c or python

/= means !=
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: