Haskell

Haskell 12: Intentional lists

20 videos

111 minutes

Hello world how are they? My name is Joseph and I welcome, for this new tutorial course Haskell and today we will see a very interesting topic that will help us in many problems that are intentional lists. Well, an intentional is a list we have seen in previous videos,

but where we filter what we want to list items or not under the conditions we seek. But the best way to understand this is with an example, it will be much clearer, how to make these filters. I will explain a little intentional structure list: good, like all ready, let's call it, ready,

like any list has to go into their brackets and the structure is as follows: here we will separate with the vertical bar, true, because this side, this side of the list will put that list we want to filter items, fine; So here we have the list we filter, here with a comma, we put the condition or conditions separated by commas and all this side of the list we put what we will show, ok.

This is the structure of all intentional lists, if this gets it, and with this can make intentional lists; but the order is perhaps a little confusing, because we have to put the list in half, then here we will show and conditions, No, this has to be separated by a vertical bar with a comma,

each condition takes a comma separation and now one more thing we have to do all the elements of the list, we'll call it by a name and that name we will put this way: we'll put an arrow and on this side as going to call each item in the list, we can call it x, true; yes ... then this is the final structure; I have made parts for us to go grabbing every idea, no.

This is the final structure, we put the list we have everything and there can already choose; but each element of the total list is called x, for example, after we showed we, if we show x, we just want to show it, but satisfy these conditions. So let's make an example, here, practical and good, then, what I will do all this out of here, I'll put here for you to go see.

Go he'll stay a little big. Well I'm going to separate more. I'm putting well and now here we have examples of such cases. All right, then, for examples; let's imagine that we want to get all the numbers that are odd, 1 to 20, for example, only odd numbers. We can do so: first, we will put the structure and the structure have not. And now here we can list the numbers;

we have to select the odd 1 to 20. I will make a list of all the numbers from 1 to 20, and we have seen this and I'll call x, so I put the little arrow there, all this is called x. Now, under what conditions we have said, because they are the odd numbers, so this means, the rest of dividing each list item x two, must be 1 and what is going to show the numbers themselves.

Numbers which satisfy those conditions, so it's just x, no. Each item in the list, from 1 to 20 that meets this condition. Well I give the intro, now when I run list, I get all the numbers from 1 to 20, they saw, because this is the system. With this system we can, then we can do anything. Now let's imagine that we do not want the odd numbers, we want to peers;

as this would be 0; but, but we do not want numbers, we want the numbers multiplied by two or by 10, to make them look. We will multiply the numbers by 10. So here, instead of showing x, x 10 and show what we will all even numbers, multiplied by 10, there have them. Indeed, would the two, four, eight, but increased tenfold, as 20, 40, 60, 80 and there we will accumulate.

That's an intention, with this list we make lists and put conditions. But besides that, it can be included in a role and put more advanced specifications. As the example has been simple and has been well, let's make an example to go a little further, to play different types and levels. Well, we here, and what we have this; I'll put here then,

this will remove and will create here a function that is called cuentaCifras then cuentaCifras will receive a list, it is going to get list; I'll put so be called l and now cuentaCifras will be equal to: then here we, structure, and we know how the structure, there and now here we'll put; for each item in the list, we've gone to him, let's put list,

as each item in the list, we receive, we'll call x and now what we will do here is say here, we say: if x is less than ten, then, as a figure (a figure), but are two numbers (two digits), we will move logically numbers that are smaller than a hundred, really, and here, for simply if we want, we have to put condition; but hey, we'll put a condition; we will work with odd,

we have seen how to work with odd, wondering if the rest is 1; but there is another way and is simply asking, with the odd function which it is odd in English, and put x, no, that element x; This returns a true or false. Let's take an example before running it, if I put here ODD 5, I will say true, because 5 is odd. If I put an odd 8, he tells me false, because it is even and is odd,

so I will return a false. So what we do here is: let's take the list we sent this function as a parameter, each element turn it into x, we filter odd odd and then say if it is less than ten, because then it is a figure (a figure) if more are two numbers (two digits), either. For this we will save, here we will load this file, load it, trust

all right and now we will make the call: cuentaCifras and parameters will go through the numbers from 1 to 30, come and here I come out of each number, this would be 1, this would be 3, 5, 7, 9 and here we enter the other numbers in 11, 13, they already have two numbers. To put here, I who first see the number and say, as I say, 1, a figure (a figure); 3, a figure; 5, a figure

would have to mix data types, we have said that can not. But for now, we will leave so not to go into depth in conminación so many things to display. But it's just an example and even here we can put an if the part we want to show. Well this has been the video this time,

that for the next video we will see how to combine intentional lists. So we have seen is an intentional list, but we can combine with each other. Hope you're enjoying it, they can give like, subscribe and share. And see more videos. A greeting.

To find new courses, subscribe. There will be no spam, promised :)

About the Author

foto de jotajotavm
José Javier Villena

Biography: Analyst-Programmer in different languages. Tutor PREMIUM platforms recognized worldwide as CodigoFacilito. Editor Cristalab articles. My YouTube Channel is sponsored by the ANAYA and LaTostadora publisher. I like to explain in detail and give several examples for the avoidance of doubt.