You are reading the article How Not Function Works In Haskell With Examples? updated in September 2023 on the website Nhahang12h.com. We hope that the information we have shared is helpful to you. If you find the content interesting and meaningful, please share it with your friends and continue to follow and support us for the latest updates. Suggested October 2023 How Not Function Works In Haskell With Examples?
Definition of Haskell notIn Haskell not is a function that is used to check the variable value, to use not in Haskell we have ‘not’ keyword. Also, it is an in-built function in Haskell, so we do not require to induce any dependency or install any library. we can use this directly inside the program. In short, if we want to check any variable value or perform any logic based on the condition based on the evaluation of variable value then we can go for not function in Haskell, it is very easy to use and handle while programming. In the coming section of the tutorial, we will see the internal working of the not function also the implementation and its usage while doing programming.
Start Your Free Software Development Course
Web development, programming languages, Software testing & others
As we discussed not function can be used to check the variable value, and it returns us a Boolean value after evaluation. Let’s take a look at the syntax of the not function in Haskell for better understating and usage for beginners see below;
not ‘your value to be checked’
As you can see in the above line of syntax, we are using not keyword to check the variable value, and it will return us Boolean after evaluation. Let’s take a look at one practice syntax for better implementation to see below;
e.g. :
not False
As you can see in the above line of syntax it is very easy to use and handle in Haskell, in the coming section of the article we will see the internal working and its usage in better detail which will help beginners to start using it while programming.
How not function works in Haskell?As we already know that now, not function is used to check the variable value, it returns us the Boolean value. It works as the opposite of equal we can say. In this section, we will first see the signature if the not function in detail given by the Haskell documentation followed by the function details. Let’s get started:
Not function signature:
1) not True == False
This is given by the official documentation of Haskell for not function in Haskell. By the use of this, we can return a Boolean value from the function based on the evolution of the function. Also, it is an in-built function of the Haskell programming language, so we do not require to install or include any dependency for this. Let’s take a closer look at the return type of not function in Haskell for better understanding see below;
1) Return type: This function will return us the Boolean value in return. It will return us the true or false as the evolution based on the passing variable as the value. we have to keep two conditions in mind which are described below;
1) not True == False: This is the first condition, If the value or variable passed after the not function is evaluated to be true then the not function will return us the false Boolean value as the result. This condition satisfies this statement.
2) not False == True: This is the second condition, If the value or variable passed after the not function is evaluated to be false then the not function will return us the true Boolean value as the result. This condition satisfies this statement.
In this way not function works in Haskell, as we already saw the conditions for this now we will see one sample example for this to understand it better see below;
e.g. :
As you can see in the above line of code we are trying to compare the value and get the result as Boolean value by using the not function in Haskell. Here we have not to import any packages to use this function inside the Haskell program. it is in built function in Haskell. First, we have defined the main module to use the not function inside it. For this, we have used the not keyword in Haskell programming, and here we are trying to check the numbers, we are checking whether 5 is greater than 10 or not. But we know that this is a false condition so not function will return us True as the result of this. That means it works opposite of equal we can say in Haskell.
ExamplesIn this example, we are trying to compare the values of the numbers by using the not function in Haskell. Also for this, we are trying to use the in-built not function, this is a sample example for beginners to understand it better and start using it while doing programming in Haskell.
Code:
main = do print("Demo to show the not function in Haskell !!") print("using not function here !!") let val3 = not (100 == 100) let val4 = not (23 < 78) let val6 = not (4 <=90) let val8 = not (1< 0) print("printing the result here !!") print("result one is::" , val1) print("result two is::" , val2) print("result three is::" , val3) print("result four is::" , val4) print("result five is::" , val5) print("result six is::" , val6) print("result seven is::" , val7) print("result eight is::" , val8)Output:
ConclusionBy the use of not function, we can check the variable value and according to it, we can apply our logic to it. We can have several not functions with some conditions inside it to check the values. This function is very easy to handle and use also; it is readable and easy to understand as well by the developers.
Recommended ArticlesWe hope that this EDUCBA information on “Haskell not” was beneficial to you. You can view EDUCBA’s recommended articles for more information.
You're reading How Not Function Works In Haskell With Examples?
Update the detailed information about How Not Function Works In Haskell With Examples? on the Nhahang12h.com website. We hope the article's content will meet your needs, and we will regularly update the information to provide you with the fastest and most accurate information. Have a great day!