cs3110 / textbook

The CS 3110 Textbook, "OCaml Programming: Correct + Efficient + Beautiful"
Other
740 stars 134 forks source link

Update lists.md #164

Closed jakubsvec001 closed 9 months ago

jakubsvec001 commented 9 months ago

I believe e2 : t list should be e2 :t:

                                           delete
                                               |
                                               v

Before: "If e1 : t and e2 : t list then e1 :: e2 : t list. " After: "If e1 : t and e2 : t then e1 :: e2 : t list. "

cionx commented 9 months ago

I don’t think this change is correct. From what I understand, x :: xs adds the element x onto the list xs. Therefore, in terms of types, x is of some type t and the list xs must then be of type t list.

The proposed change would mean that x :: y combines two elements x and y (of the same type) into a list. But this is not what the constructor ( :: ) does.

We can also see this in utop, for example by choosing t as int:

# 1 :: 2;;
       ^
Error: This expression has type int but an expression was expected of type
         int list