Haskell

Haskell 09: Lists Functions Part 2 of 2

20 videos

111 minutes

Hello World How are you? My name is Joseph and I welcome this new course Haskell, we're doing and in today's video we will see a little how there are functions that can help us to then change lists, make products, calculations with them. So, well, I'm going to create two lists, I have here the last time; a list is going to be and this will be the other; on the list to be called 'List'

I have other numbers and have internal lists, this time character. Well, then, if I use the reserve and function and make the reserve list; Hey !, sorry, not reverse book is what I want to do is reverse. Reverse list, which makes me is that I will list all I flipped, so it puts me in reverse, that they saw no, the end to the beginning; list but still worth the same, no change will value,

only that I was shown upside down, but the list value appears intact. If I do the same with the other, I put here for a reverse of listaDelista, it makes me change, but I find the change of the elements, the indices is ready; but they saw that I can not change, 'dc', 'ba' You see, only he changed positions; all this first set goes to first place and everything is set goes to second place.

So, here they saw, passing the set, but without an alteration of that order, I was there just that. Okay. So is is another function: the reverse. Now, as would then for more functions because notice. I hereby make a take 3, take 3 list, I take the first 3; and if I make a list take 5, oops, I have to tell you where. I'll clean this, so it is better. A take 5 list and take me five,

and if I do a take 100 list, there's a hundred, but I take that no, no, you can not take more. Okay. Like I can take the first X items in a list with the take function, although the list value appears intact; I can also do so they show me the elements of a list, but I removed the first X elements; that is to say,

show me to take the first X and another function called, drop me remove the first X elements and takes me the rest. For example, because if I; I have listed here, no. They are seeing the value list itself here and make a drop 2 list, I take out all there, but the first two I remove them, but still worth the same list; if I want to remove my top 5 list items,

me out of there after the sixth. Okay. But list seems intact. And if I make a drop 100 list, therefore they can not take me a hundred, because I removed that no, no, just do not get anything. Okay. So you saw how to manage what shown me or not, you can do to some and I removed what I can do to show me other, ok. Then we will see more features,

remember at the very beginning, we say that in Haskell has implemented, by default, some functions. For example: min function, if I say I was 8 and 3 the minimum, but was not prepared to receive several parameters, no; I if I gave several, nope, did not work, I could only receive two; but how I can do now and I want to calculate several; good here I have list, then now yes,

with the minimum function, if I here call this function, it will say that you pass the minimum list; yes it will happen to me minimum list. There is already yes I can send, bone can make a comparison of several numbers, as long as everyone belonging to the same list. Similarly, instead of putting minmum list, I can here put minmum and then I can simply pass a list, this created as I want.

I can do so directly and pass a list, and I will leave the number. Okay. Similarly, with the maximum function, if I make a maximum list, I get a 7 and I do in this function, here I make a maximum of all this, then tells me that is a 9. Now, I do want to, well, this can also be done with the other, listaDelista, the maximum is a 'cd' because they are those characters with a higher value,

there they saw, no. Then, as now it would be yes, I want to do calculations with lists. Again I have the list here and now if I say or here you add up all the items in the list, yes I add all these numbers give me a 28, if I make the sum to all and also, if I here for a product from a list, for example, 1, 2, 4, I was going out a multiplication; one will multiply all followed; as one of two,

two; two by four, 8. There you saw, no, it would be like if I put as follows: 1 x 2 x 4 x 5 x 6 x 7, and they saw what I get, yes, It is the result of the multiplication. If I do it in a list, I put it like this: 1, 2, 4, 6, 7, I get the same result; with product, there I am multiplying and finally I can also check if an item I want, I ask if that

element is in the list or not. For example, if I am referring here, now, I am ready and I want to ask if there is ready some a number, for example, the number eight, put it well, with French quotes, forgiveness, with the French accent there. Pongo number 8, Is it a list item? And he tells me it is false, because on that list there is an 8. But if I ask for 4, yes, because if it is with a 4 gives me true.

If I go to the listaDelista, here I have it here and I do the same and ask yes 'cd' is an element of listaDelista, I will say yes; but I wonder if c is an element of listaDeeista, I will say no, because c as such is not an element; is an element of an internal list; listaDelista, come I will say, well, for starters, I give up an error; because ... actually no, it can not, it makes no sense what we are doing,

no, that's not true, ok. As would be then, if we now ask internally, to refer to an element within an element, as a list within another list; because I can put: yes cd, no forgiveness, If c is an element of listaDelista in position 1; there does tell me yes, because, remember this is the 0 position, this is position 1,

then c is an element of this position, that is certain, they saw themselves there; also, because if I wonder the same thing here, but it is an element of listaDelista in position 1, I say no, but at position 0 tell me yes, that I have it. Well, this has been the tutorial this time, we have seen many functions and manage how to make calculations as shown or not, as these

lists and in the following video we will see even more things that are interesting about Haskell. I hope you will be enjoying the videos. They can give like, share or subscribe and send 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.