20 videos
111 minutes
Hello world, how are you? My name is Joseph and I welcome this tutorial Haskell course we are doing. This time we will see a little how to use functions that we have created in external files which are going to make the call. So here I have my file, called haskell.hs I have it in the same directory where I am running Haskell terminal that comes with the installation, right? So here's what I'll do is:
function will create me here and from here I'll call her. They will see that it is simple. For example here in Haskell, I will create me a role and I will put its name, which will be called sumaDiez. And I'll say this sumaDiez will receive one parameter, which will put it'll be x, right? And this function will be equal to what they are going me 10, but I want entiedan this: when I put this here like'm not saying that x equals this. What I am
saying that is the same is the function that I pass a parameter. So really, if you want it I put here otherwise ... Actually what I am saying, I'm not going to put that account, it is just so you understand, it's like sumadiez were equal to x + 10, you understand? What happens is that the parameter that I'm getting what I have to put before the function declaration in the function header, before saying what is the same all function
because this process is equal to what all function will not be able to calculate if we have not said that parameters will have the function. So the first I have to put the parameters received, the name will have and then later when I do I make matching the equal of what it is like function, not this value. Because if, for example, was a function that has two parameters and here I put x and, then, what does that and is equal to this? Does not mean
all function is equal to this, right? Then I put this here and take it off because it does not work, it was only as an explanation. So I've created a sumaDiez function that will receive a value and return that value will more than 10. I keep Yo, come here and now I charge this haskell.hs file How do I do that? As I lay: l and now I tell you the filename, haskell.hs. I compiles, tells me ok, there is no problem, and now you see that changed this line
the prompt. Now you tell me I have here a main, as has already loaded functions previously did not have and is properly and has memory that function and now I can make a call to that function. I will put here will give me sumaDiez 7 and 17, did you see? And now this I can combine. I can say I of the number next of sumaDiez 14, the next number of sumaDiez 14 will they be 24, and the next will be 25. There you have, did you see? Then this is the way
systems combine all these functions and create functions. If I now, for example, this sumaDiez you change the name, or good, I change the structure, even if here sumaDiez, what we do is subtract, okay? Even if that name, but hey, to see a little how to reload a file if already here He has undergone a change, how to be reflected here, because if I now call here and I put sumaDiez 8 I get 18, because it was not updated. So,
How do I update? Well then I have to reload. Then I can do so and now if I reload and give him a sumaDiez 2 nd -8 me, because now the rest, okay? And if I give now sumaDiez more, then, as has already changed again if I make a call I will continue subtracting. But if I do this: A: r, which is like a reload, no longer have to put even the name. Just to make a self-loading reload it, you see? And it was loaded
with the file I'm working: haskell.hs. So, now you will have this value. If I now give me here sumaDiez 90 I will come out a 100. And here also, as we saw before in other videos, if I put a decimal number no problem. This is when I want to make a call to a function that has a value, but what if I want here is to put two numbers? Then I put here sumaNumeros and this returns x and x + y, right? I'll spend two numbers
by parameter and I will return the sum, which is the same as happened when he wanted to calculate the minimum number, which put the function and then put the two numbers I want to calculate the minimum, right? Then I make a call here ... well, first I have to make a recharge to recognize me the syntax of the file is and is not, but has these functions. And now if I call sumaDiez will not work, because it already ceased to exist. Now
sumaNumeros called. Then I put sumaNumeros and now I put the 6 and 2, and I will leave an 8. It's simple, but did you see how the weight value It is in the functions, not the variables? That is the key to Haskell and if that is done in the head can understand more issues will be advanced. Well, I hope you is enjoying this course. They can give like, subscribe and share and see you in following tutorials.
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.