20 videos
111 minutes
Hello world as they are, my name is Joseph and I welcome this new course of Haskell tutorial, and we are doing good because this time we will look a bit like to refer to different elements of our list with the position occupied OK. So here, for then we are going to explain a little first that if we use a reserved word
Let that allows us to create a list to name and associate it and so being able to use that name put 'let list = [6,7,8]' because I have already stored there as if I now say 'ready' there I get [6,7,8], then what happens if you are used the concept of 'arrays' arrangements will understand that each of the elements of an 'array' of occupies a position has an index,
the first is the 0 position, the second position 7 is not, as well as have numbered; Haskell just happens each item in a list, it has a position and to refer to them using the operator '!!'. So for example if I want here I refer to the item first as I do so I put 'list !! 0' which is the number you want to refer me carrying a 6;
here I say 'list !! 3' for meda error because there is no 3 position remember that this is different length than the 3 position, if we refer to the latter in this case, as the latter it is has 3 position 2 'list !! 2' as there meda 8. Haskell may include lists of lists, then I here for example'll put that 'let list = [[1,2], [3,4]]' Now if I put 'list'
I get '[[1,2], [3,4]]' as each belonging to different items in the list so that if I refer to the item 'list !! 0' my list I will leave 1 because I element 0 is this [1,2] are elements which are separated by commas, This is the first element [1,2] and this is the second element [3,4], the first element is a list itself if so when I
I get that own reference list is the element zero OK. So now what you already imagine that when I make lists I can not do is mix lists different values so I can not put here 'let list = [[1,2], [ 'a', 'b']]' then I have a numerical list here and I also have a list of characters, because that can not be or is one thing it's another recall
always this concept of values, here let's put it as it was before mede mistake to not 'let list = [[1,2], [3,4]', as a serious attempt to access this element here [1,2], well, if I do this 'list !! 0' meda that element [1,2] and if I now do so, 'list !! 0 !! 1' looked sale 2 I'm accessing in first element with index 0 within that I access
the element with index 1, then this element 0 [1,2], this is the index 0 [1] is zero zero, and this [2] uno zero, we're always working on this [1,2] is zero and this is the one [3,4] global lists so within this element which it is a separate list this is the first [1] that has a zero too and this [2] is the second to have one;
and this [3] is zero element [3,4] one and this [4] is one element one and if I put here 'list !! 1 !! 1' will make a 4 well. Then the operator admiration '!!' I can access the key elements for good in the next video we will see some other words reserved for results based on our values that have the functions list that are already implemented
handling of lists I hope you will be enjoying the videos so they can give you like, subscribe share and send you greetings.
About the Author
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.