From the course: Programming Foundations: Discrete Mathematics

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Use SML to create lists

Use SML to create lists

From the course: Programming Foundations: Discrete Mathematics

Start my 1-month free trial

Use SML to create lists

- [Voiceover] Another reason to use the SML programming language or the Standard Machine Language is to create list. List can be used to model sets. To create a list, you simply list all the values in brackets separated by commas. For example, I can have a list of integers. A list is similar to an array and it even must contain all values of the same type. Let's create another list. This list I'm gonna give a name. I'm gonna say val rainbow equals and I'm gonna give it all the colors of the rainbow. So I use my square bracket. And I have to put the names of the rainbow in double quotes since they're strings. So we'll start with Red and list all the values. Okay, now I have a list called rainbow. Once we create a list, we can perform operations on the list such as getting the first element. So let's go ahead and get the first element from our list called rainbow. We used the command hd. So I'm gonna say val first equals hd and in parentheses I'll give it the name of my list rainbow…

Contents