20 videos
111 minutes
Hello world as they are, my name is Joseph and I welcome this new course haskell tutorial. Where we will turn in this video how the structure if it works in this language. So then let's make a function where we will here create a function that will be called divisible and will analyze, if two numbers are divisible or not here put the two numbers we will choose
as parameters x and let's see what things are like this this feature, = refers to the value that will function and will have to return, and not to a change in the value of the variables because the value of the variables is always the same, so we will not only touch the value, ok function. So here I will ask the following divisble x y = if and will put here if the rest that meda is equal to 0, the rest will bracketing
to give me an overall result, not that condition is putting brackets if no condition if not enclosed in parentheses, only what I am doing here is that the value of the rest for after all that equals zero me to do that as they did so I put it here, divisible x y = if (x 'mod' y) == 0 then what I do is that value that will be divisible
It is equal to 'divisible' and if you do not have to put 'not divisible' and listen. This is important in haskell is mandatory if all have her then and else you can not be ignored any circumstances all that can be put on a line, but I think that is a little better, but better to see it has not been better to understand the language better, but if you put an 'if' has to put what if is correct
and that always happens if wrong or it is mandatory to always put the 'else' and remember, as the condition is not put in parentheses if I put this if (x 'mod' y) == 0 the rest of x and y is zero then and this value then 'divisible' is what I'll match function and but else 'are not severable' is going to be worth what the function is not going to be worth or x, or y.
Now I come here and I'll make a charge: r haskell.hs this file compiles me perfect and I here divisible April 8, are severable and if I say here divisible March 8, They are not divisible because I saw here can also check for good. To make these if I'm going to rename a divisible and here I will see if it is greater then put esMayor will receive two numbers x and (y) now here say if x> y, then here put then 'greater'
and but else 'is no more' and here I save the file charge: r, to recognize the new role I now call esMayor put here. The important functions can not start with this case is important function name must start with lowercase but hey that's already a small detail. Here I put greater Sept. 3, is greater and if I tell you is greater Feb. 6, is no more saw this is how the if structure
if there is then the question of who want to check without brackets (at least here you have to make a call to a function) is set, then there is if you put parentheses as we saw in the previous example simply because they are making a call for any other questions so that the new value is best recognized as a proper value after the then and else and then good because this is so for example we do another test,
we will give us will only add ten numbers that are greater than 20 for example then here I say sumaDiezAMayoresQueVeinte, It is a very long name but good bill here for a parameter x and then here say if x> 20 then but then a x + 10 x else but will stay the same for I say now here sumaDiezAMayoresQueVeinte 30 gives me 40 if I spent a 5 returns me if I step 5 20 20 me back because there is greater
and here I put else 'is no more' and keep going to see what happens, it does not compile me because haskell You can not be here to tell you here is a numerical value and here I say it's string value that is not possible or one thing or another but they saw what we discussed in other videos that the data type is something that is strictly a single variable can not walk to walk looking at some variables
with others, you can not go adding integers with strings doing that sort of thing, because if we try to x from a numerical point may well be that is an integer or a decimal that is another question, but we can not give the exact value of numeric or string it, then here we can not put a message because we're treating it as a number, then we have to do is leave it as is, without changing anything else we can not override this
because that will not do anything because it is mandatory then put it as something must be put simply leave it like this so that no haiga no change in that situation. Well this has been the tutorial to see how has been the structure of how if it works in haskell I hope you like can give you like, share, subscribe and see you on these videos.
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.