前一段时间写了不少Python的爬虫程序, 为此还看了极客学院上的一些教程, 现在来简单总结一下. 主要介绍用requests + lxml的方式, scrapy的话之前写 …
this week: programming-in-the-large using the module system of OCaml.
in large project: mangage high number of definitions → abstractions built on top of other abstractions.
dot-notation: access module …
functional language:
but imperative features are useful:
syntax for functional expr: function some_identifier -> some_expr
the type of the functional expr is t1 -> t2 where t1 is the type of some_identifier, t2 is type of some_expr
ex.
function x -> x + 1;;
(function x -> 2*x) 5;; (*annonymous function*)
the previous way of defining function:
let …
Last week, we only defined flat data structures which are nice to aggregate values but quite limited when you try to structure values.
This week: algebraic datatypes.
⇒ change the return type to a type query_result, which can be either of these:
this week: structure code with types: tuples, records, arrays.
type type_identifier = some_type to define a new type (type_identifier is synonym/abbrevation of some_type) type_identifier must start with lowercase letter int, bool, string, char ... : to add …this week: discuss how to handle events in user-interface — MVC, functional reactive programming.
Traditional way of handling events: observer Pattern (MVC). Used when views need to react to change in a model.
MVC: model-view-controller for user interface
This week: scala for imperative programming.
So far: pure functional programming
→ side-effect free: therefore time doesn't matter.
Any rewriting that terminates lead to the same solution. (Churcher-Rosser Th)
Now: mutable states
Stateful objects: objects can have state that change over time. (state is influenced …
Rich type system and polymorphism in ocaml. Types are infered not declared.
Basic types: int, bool, float, string, char, ...
value: $-2^{62}$ ~ $2^{62}-1$ on 64-bit machines.
ops: +, -, *, /, mod (reminder: / is integer division)
# 3+2*4-1;;
- : int = 10
# 5/2;;
- : int …