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


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:

  • an error
  • a new database (in ...

this week: structure code with types: tuples, records, arrays.


primary use of types: document your code

  • use 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
  • already known types: int, bool, string, char ...
  • use : to add ...

this week: discuss how to handle events in user-interface — MVC, functional reactive programming.

Lecture 4.1 - Imperative Event Handling: The Observer Pattern

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

  • Views can announce themselves ...

This week: scala for imperative programming.

Lecture 3.1 - Functions and State

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 ...

1. BASIC DATA TYPES: int, bool

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 ...

Lecture 2.1 - Structural Induction on Trees (optional)

Generalize the structural induction on list to general structures like trees.

To prove a property P(t) for all trees t:
* show for any leave l, P(l) holds
* for each internal node t with subtrees s1...sn, show P(s1)&...&P ...

上次捣鼓pelican博客系统还是在2012年, 那时farseerfc学长就提供了无私的帮助, 当时非常兴奋写了这么一篇简单的教程.

这两天捣鼓了好久 终于把博客升级到了pelican3...

新的pelican貌似希望使用者把写作的内容和生成的网页分成两个repo管理, 我嫌麻烦还是把它们都放在了一个repo下面: https://github.com/X-Wei/x-wei.github.com 这个repo包含了生成的网页以及我写作的内容(在pelican_dir目录下面).

换了超赞的新皮肤, 这个是farseerfc学长定制的bootstrap3主题, 非常精美. 学长的版本包含了繁简英日翻译以及导出pdf/png什么的按钮, 功能非常全, 不过直接拿来用不太合适, 比如我就不需要博客的日语版... 我实际是用的silverchard对farseerfc学长主题的修改版. 再稍微修改了一下配色什么的...

如果想要做一个类似的博客, 下面是一些步骤:

1. 安装软件

首先安装pelican3以及其他一些python module (另外个人建议新建一个virtualenv在里面搞):

pip install pelican jinja2 py3babel babel beautifulsoup4 markdown ...