Haskell

Haskell 13: Double Intentional lists

20 videos

111 minutes

Hello World How are you? My name is Joseph and I welcome this new course Haskell tutorial where we will learn today how to combine Intentional different lists. So good after seeing the structure of an intentional list in the previous video. Today we will see a little how we can do to combine several. So, first, I am creating here, my list

and I'll explain a little bit like the combination. The structure is the same as always, we have already seen, uh, I parted with this horizontal bar and here we, here the list and then the condition comma and then we want to show; and you saw this all this time, what if we put a list here before, because here we will put two lists. For example, I will create a list,

, Which elements will call the X and here what I create are all numbers from 1 to 20, for example and this other list, I'll have here now are the numbers from 1 to 100 and this list, the numbers they'll call with the letter Y. So I put so with the same structure, with the arrow. ?, Well then, what I have here ?, then I have on one hand a list of 1 to 20 with X

and another 1 to 100 with the Y. And now here and I put the conditions, what I do is: take the first list of X provided that X is less than 10; so I'll put while X is less than 10, so we will take 1 to 9 and on the other hand, with commas, separate conditions, on the other hand, I'll catch Y, the numbers are divisible by 10; ie 10, 20, 30, 40,

only those nothing more than the multiples of 10, so I'll put here so the rest 10 is 0, so that are multiples of 10. And I'll do here now, once I have this, I'll add X + Y; so I will therefore 1 to 10 I will 11 1 to 20 I will 21, 1 to 30, 31. This is how I go out, I run, Hey !, sorry I'm missing here, separating this element, now if I run

The two lists, they are separated by a comma to separate a list of the other and now when I list there are, what I have told you before 1 with 10, 21 ... 11; 1 with 20, 21; 1 to 30, 31 to 40 and up to 90 and up to 100, 101. Now with 2 because we're touring this list, this, 1 to 10, 1 out of this list of X and 10 out of this list, the Y

and now, once we have gone through all the 1's, 2 and we move out, the 2 again, with all the elements Y's, 2 with 10, 12; 2 with 20, 22; and with all the 2's, and then we started with the 3's, we started with catorces. So on until 9; we arrived here, there you are, right? So, well, then, this is the way to combine a list with others, is a matter of putting each comma-separated list;

not as I did before, separated by comma, name them and set the conditions, and then what do we do with those items in the list? It is very simple good in this example, then, I have made this operation may not have much logic, but it is for you to see; there you understand. So now what we will do is, as we have seen simple intentional lists and lists combinations. Well, let's see a little logic

they have these things and we can do with it, for example, here in this file Haskell.hs; for I will create ... I ... we will develop a function that calculates us the length of the list, this, here, then you already know how it is: if I here put the length of list, I get here is 90 items in total; if I add all the numbers that have taken out 90 elements.

So we're going to do us a specific function; developed by us, tell us how many items have a list. What's going on? You here, when you run this or any other intentional list, we've seen, you've seen in previous videos, as examples, I always returned, it is always a list, here you see it, bone, intentional return a list list.

So here, we will create a function that will be called length that they receive as parameter a list logically and now we are going to have to say So how many items are on that list; then how do we do that? Well, then let's think a little. We are saying that all intentional me list returns a list, so that if I put my structure here and get the list that I receive,

all elements of the list, I'll call Xy now here, instead of displayX, which will show for each item, instead of displaying X, I'll show it is a 1. Well? So, whatever it is, what we have, they are going out all 1's; In fact, let's make an example here; if I put here as well, and put 1 ... uh ... list; I put here so that I appoint X

and now, they're going to have to leave ninety 1's, because if we have seen that there are ninety elements, each element I will produce a 1, there you have it right? Ninety 1's, okay? So I now with this, as it will take for 1, each element will give me a 1, if I use a function here we have already seen in a previous video, operations with lists fun ... if I here put a sum, what I do is that; each of these elements sum

And what will give me ?, because the sum of all elements, bone, I will say how many items there. Because it will add 90 1's, I will leave 90, which is the length of each. So, this, if I keep it here, and here charge the Haskell.hs file, Oh sorry; is only one point with two eles. Haskell.hs, and now here I compile call length, I here ... you will see, I have listed here;

Hey, sorry, we will create a list that will be all the elements that go from 1 to 30; I show here and that's it. Then, I'll call the length function ... and I'll pass the list as a parameter. I call list and giving length, 30; that is, what if I had done the length of list it is 30, which is the same, but what he has done has been to become all these elements into 1's

for each element and add them into 1 has joined me what ?, Well Well, then, this is a way of combining things we've seen before, we'll see another example, what we now here. Let's change this function, let's make another function that is called out, not better mostrarVocales and we pass a sentence and what to do here, it is only, show vocal, and will only put here, receiving a sentence and now what are we going to do here?

As we will show, we will put here the structure to go a little watching this sequence. So here we catch phrase and each element in the phrase of this list, each item, we will call letter, okay? So here what we will do is, will only display items, yes letter equals to or other status, no forgiveness, forgiveness, letter belongs to the list of vowels: a, e, i,

I'm putting well to make it look, o and u. Before going to do, if letters equals to, or letters equals e, it is equal to i, but it is not possible because a letter will never be equal to all, so I have to do it this way, right? If I put here as a condition, letter, equal to a and other conditions, which also meets, also this condition, equal to letter e. As this is not possible because you never

They will be able to fulfill all these conditions or one thing or another; so this, I would do before I realized that was wrong, It has to be this way, right? Tucking, checking that letter belongs to this group, to this list and now we'll show; it just is, letter. The letter, which meets this condition, so the entire phrase, letter by letter, analyze what is a vocal and vocal shown,

I'll save, here file charges and gives me an error. So, well, I'll see that ... that, that error can be here; ah already here, I do not put a comma to separate to separate this, then now yes, I keep charge and now I will be no problem and now, we are going to call this function mostrarVocales and, well, we have said that I have to pass a list, right? So I could pass a list as well, as we are seeing.

I can well pass a list and I get the O and A, but remember that text strings are considered already as lists itself. So I, if I put here: hello world, simply because I have to write all brackets, put quotation marks me out the vowels. O, A, U and O again, okay? So with this feature that I just created, then I can get the vowels, I can get how many there are consonants,

how many letters are the letter A, the letter B, that all I can do right? If I say here, let's phrase, that takes me, how many letters are C. I here give to reload and now here show, well, heh; mostrarVocales not, we will call, that call, mostrarC, then I here then, what I do is recharge; I say mostrarC and passed one sentence: the house is expensive, has two right? I will leave two right?

So I now what you could do is to combine a little of what we've done before, right? So, now I can do here, another function that is called sumarC, be equal to a list. Well, what I do, it is that this function receives a ... a, a chain, a chain C of C's and what I will do is add, as we have done before, each item we will become one, and here we are going to do is call mostrarC

passing as parameter that sentence right? So if I put here, mostrarC and control the phrase right? What would you do in this case is sumarC call, passing the sentence, passing the sentence itself. So this phrase mostrarC, this phrase, when the pass to mostrarC, I will return the only filtrándome chains; I will return a filtered string, only the C's and now, this element of each chain,

if I here; each element of the chain, convierto; I'll call X, to call in some way and I became one, and I sum, I will tell you how many C's, has the phrase. I this I charge fee here and now I have to do is call sumarC and I'll put: the house is expensive and I get that two C's Understand? I mean, here we have done two things: we simply returns a list,

with the C's that there are these right ?, and in the other, what we do is what we have done before, we are using that idea, transform this into one and add them; and so we know how many C's there. I can do this for any letter, do we not ?, let's, I will not change the names to sentences, functions, but even if you say sumarC, but hey, we will, to do it as if fueranA's¿No?

I now here, we do the following, this laid the charge and now we go to, even sumarC, but will actually count how many A's. I here, I put: I have an apple that is very rich. There are many A's: 1, 2, 3, 4, 5, 6. I give and tells me I have six A's, they saw. Well, this is how to combine, uh, we have seen how to combine different intentional lists in the beginning of the video

and how do intentional lists functions and match with each other functions, to go getting different things; you want to achieve. I hope you will be enjoying these videos are very interesting, and saw a little, that the structure of Haskell, is not so much based on variables but have the weight of the information lies with the functions and we must see how to reuse one function to another,

to fulfill what we are pursuing. Well, they can give like, subscribe and share these videos, I hope you like them and we will see the following tutorials issues. I send greetings.

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.