From c85de95f6eb1ab28f304cc1bea375c2685304f60 Mon Sep 17 00:00:00 2001 From: Jim Date: Sat, 31 Jan 2015 23:48:14 -0500 Subject: [PATCH] update week1 notes --- week1.mdwn | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/week1.mdwn b/week1.mdwn index c8e953e9..0c683e8a 100644 --- a/week1.mdwn +++ b/week1.mdwn @@ -224,7 +224,7 @@ Sequences are containers that keep track of the order of their arguments, and al {10, 20, 30} -Whereas the sequences `[10, 20, 10]`, `[10, 20]`, and `[20, 10]` are three different sequences, `{10, 20, 10}`, `{10,20}`, and `{20, 10}` would just be different ways of expressing a single set. +Whereas the sequences `[10, 20, 10]`, `[10, 20]`, and `[20, 10]` are three different sequences, `{10, 20, 10}`, `{10, 20}`, and `{20, 10}` would just be different ways of expressing a single set. We can let the `&` operator do extra-duty, and express the "consing" relation for sets, too: @@ -264,17 +264,17 @@ and these will all be of the same type, namely a sequence of numbers. You can ha or a sequence of sequences of numbers: - [[10,20], [], [30]] + [[10, 20], [], [30]] An excellent question that came up in class is "How do we tell whether `[]` expresses the empty sequence of numbers or the empty sequence of something else?" We will discuss that question in later weeks. It's central to some of the developments we'll be exploring. For now, just put that question on a mental shelf and assume that somehow this just works out right. -Now whereas sequences expect homogenously-typed elements, and their length is irrelevant to their own type, tuples are the opposite in both respects. Tuples may have elements of heterogenous type, as our example: +Now whereas sequences expect homogenously-typed elements, and their length is irrelevant to their own type, mulivalues or tuples are the opposite in both respects. They may have elements of heterogenous type, as our example: `(0, 'true,` λ`x. x)` -did. They need not, but they may. Also, the type of a tuple does depend on its length, and moreover on the specific types of each of its elements. A tuple of length 2 (also called a "pair") whose first element is a number and second element is a boolean is a different type of thing that a tuple whose first element is a boolean and whose second element is a number. Most functions expecting the first as an argument will crash if you give them the second instead. +did. They need not, but they may. Also, the type of a multivalue or tuple does depend on its length, and moreover on the specific types of each of its elements. A tuple of length 2 (also called a "pair") whose first element is a number and second element is a boolean is a different type of thing that a tuple whose first element is a boolean and whose second element is a number. Most functions expecting the first as an argument will crash if you give them the second instead. -Earlier I said that we can call these things "tuples" or "multivalues". Here I'll make a technical comment, that in fact I'll understand these slightly differently. Really I'll understand the bare expression `(10, x)` to express a multivalue, and to express a tuple proper, you'll have to write `Pair (10, x)` or something like that. The difference between these is that only the tuple is itself a single value that can be bound to a single variable. The multivalue isn't a single value at all, but rather a plurality of values. This is a bit subtle, and other languages we're looking at this term don't always make this distinction. But the result is that they have to say complicated things elsewhere. If we permit ourselves this fine distinction here, many other things downstream will go more smoothly than they do in the languages that don't make it. Ours is just a made-up language, but I've thought this through carefully, so humor me. We haven't yet introduced the apparatus to make sense of expressions like `Pair (10, x)`, so for the time being I'll just restrict myself to multivalues, not to tuples proper. The result will be that while we can say: +Earlier I said that we can call these things "multivalues or tuples". Here I'll make a technical comment, that in fact I'll understand these slightly differently. Really I'll understand the bare expression `(10, x)` to express a multivalue, and to express a tuple proper, you'll have to write `Pair (10, x)` or something like that. The difference between these is that only the tuple is itself a single value that can be bound to a single variable. The multivalue isn't a single value at all, but rather a plurality of values. This is a bit subtle, and other languages we're looking at this term don't always make this distinction. But the result is that they have to say complicated things elsewhere. If we permit ourselves this fine distinction here, many other things downstream will go more smoothly than they do in the languages that don't make it. Ours is just a made-up language, but I've thought this through carefully, so humor me. We haven't yet introduced the apparatus to make sense of expressions like `Pair (10, x)`, so for the time being I'll just restrict myself to multivalues, not to tuples proper. The result will be that while we can say: let x be [10, 20] in ... @@ -298,7 +298,7 @@ but in other examples it will be substantially more convenient to be able to bin `let` ` f be` λ `x. (x, 2*x)` -` (x, y) be f 10` +` (x, y) be f 10` `in [x, y]` which will evaluate to `[10, 20]`. Note that we have the function `f` returning two values, rather than just one, just by having its body evaluate to a multivalue rather than to a single value. -- 2.11.0