val a = [1,2]; val b = hd(1);Your diagram would look like this
You should draw the arrow from b to the value 1 rather than the box that points to 1, because hd returns an int, and not a list. If it returned a list, then you would draw the arrow to the box (but it doesn't, so don't do that).
- val (x,y::z) = ("dog", [2,5]); stdIn:20.1-20.30 Warning: binding not exhaustive (x,y :: z) = ... val x = "dog" : string val y = 2 : int val z = [5] : int list - it; val it = () : unit -ML will create a different space for each of x, y, and z, so be sure to draw a space for each of them. The tuple that was used in the pattern
(x,y::z)
doesn't get bound to anything, as you can see, it doesn't have a name, and it isn't bound to it
.@
. It is an infix operator and its parameters must be two values of type list. Here is an example.
[1,2,3] @ [4,5] = [1,2,3,4,5];Here, the list
[1, 2, 3]
and [4, 5]
are concatenated together to make a new list [1,2,3,4,5]
. An important thing to note here are that both arguments must be of a list type, so
3 @ [4,5] [3,4] @ 5 3 @ 4would all not work, because in each one of these cases, at least one of the arguments are
int
, rather than lists. (Side note: something thing to note is that the @
operator isn't really anything special, all it actually does behind the scenes when you run it is recursively construct a list using ::
cons.)