Yao Lirong's Blog

Yao Lirong's Blog

Innovation For Everyone

Kinect as Web Cam

高二升高三暑假参加夏令营让我白嫖的 Kinect2,大材小用当做网络摄像头来用

Look Back on Cornell 20SP

CS3110 Data Struct & Functional Programming

Ranting

When you find yourself saying, “I don’t know,” be sure to follow it up with “ - but I’ll find out.” It’s a great way to admit what you don’t know, but then take responsibility like a pro.

The Pragmatic Programmer, Ch2. The Cat Ate My Source Code

Modules

From Textbook: OCaml Modules


Structures

Semantics

The first letter of a module’s name should be capitalized.

1
2
3
module ModuleName = struct 
(* definitions *)
end
Higher-Order Functions

From Textbook: Higher Order Programming


Introduction

  • higher-order: functions as values, you can pass functions as arguments into other functions, functions at the same level as other variables
  • lower-order: languages like C, functions as something higher than other variables

Pipeline is a higher-order function.

1
2
3
let pipeline x f = f x
let (|>) = pipeline
let x = 5 |> double (* 10 *)
Standard Data Types

From Textbook: Standard Data Types


Lists

Building Lists

The empty list is written [] and is pronounced “nil”, a name that comes from Lisp. Given a list lst and element elt, we can prepend elt to lst by writing elt::lst. The double-colon operator is pronounced “cons”

Functions

From Textbook: Functions


Functions

Definition: let f x1 x2 ... xn = e (f is the function name; xi is input, and there can be multiple inputs; e is the output)

We can think of t1 -> t2 -> u as the type of a function that takes two inputs, the first of type t1 and the second of type t2, and returns an output of type u. Likewise for a function that takes n arguments.

A function is already a value (that’s how you assign the value “function” to a variable name), so there is nothing to be evaluated when we evaluate its dynamic semantic.

avatar
姚立嵘 Yao
让每个人享受科技的乐趣 (Innovation For Everyone)