Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
Haskell Articles
Page 7 of 13
Haskell Program to check a given number is finite or not
In Haskell, we can use isIEEE, isInfinite and isNaN functions to check whether a given number is finite or not. In the first example we are going to use (isIEEE n) function with if-else statement and in the second example, we are going to use (isInfinite n) function. And in third example, we are going to use (isNaN) function along with (isInfinite n) function. Algorithm Step 1 − Program execution will be started from main function. The main() function has whole control of the program. It is written as main = do. Step 2 − The variable named, ...
Read MoreHaskell Program to get the numerator from a rational number
In Haskell, we can use numerator, div, quot and gcd functions to find the numerator from a given rational number. In the first example we are going to use numerator (r) function and in the second example, we are going to use (n `div` gcd n d) function. And in third example, we are going to use (numerator r `quot` gcd (numerator r) (denominator r)) function. Algorithm Step 1 − The Data.Ratio module is imported to use numerator function. Step 2 − Program execution will be started from main function. The main() function has whole control of the program. ...
Read MoreHaskell Program to calculate the value from the given fraction and exponent
This haskell tutorial will help us in calculating the value from the given fraction and exponent of a number. To find this, the input is taken as fraction and exponent, and its corresponding value is computed. Algorithm Step 1 − The “Data.Ratio” is imported to work over fractions. Step 2 − The calculateValue function is defined Step 3 − Program execution will be started from main function. The main() function has whole control of the program. It is written as main = do. Step 4 − The variables named, “fraction” and “exponent” are initialized. ...
Read MoreHaskell Program to create a simple recursive function
In this article, we are going to understand how to create a simple function in Haskell using user-defined function. Here, the user-defined recursive functions are defined that will contain base case and recursive case. Then, these functions are being called recursively by passing the argument to it. In all the examples, we are going to define certain functions to perform certain tasks. All these functions include, base and recursive cases. The function defined includes factorial, fibonacci, sumList, etc. Algorithm Step 1 − The user defined recursive function is defined with base and recursive case. Step 2 − ...
Read MoreHaskell Program to return multiple values from the function
In Haskell, we can return multiple values from the function by using user-defined function along with tuple, custom data type and Maybe data type. In the first example, we are going to use (myFunction = ("Hello, World!", 42)) and in the second example, we are going to use (data MyData = MyData { stringValue :: String, intValue :: Int }). And in third example, we are going to use, (myFunction :: Maybe (String, Int)). Method 1: Using Tuple In this method, a function can return multiple values by using a tuple. A tuple is a data structure that holds multiple ...
Read MoreHaskell Program to return a string from the function
In this article, we are going to learn how to return a string from a function using user-defined function along with record syntax and let binding. In the first example, we are going to use (myFunction = "Hello, World!") function and in the second example, we are going to use (myFunction = stringValue myData). And in third example, we are going to use let binding, (myFunction = let str = "Using let binding!" in str). Method 1: Returning a string from the user-defined function In this method, the user-defined functions are defined that will contain the function definition and return ...
Read MoreHaskell Program to pass a string to the function
This article will help us learn how to pass a string to the function in Haskell with identity function and lambda expression. In the first example, we are going to use (myFunction inputString = inputString) function and in the second example, we are going to use (myFunction = id). And in third example, we are going to use lambda expression, (myFunction = \inputString -> inputString). Method 1: Passing a string to the user-defined function In this method, the user-defined functions are defined that will contain the function definition with some returning value and is being called by passing a string ...
Read MoreHaskell Program to return an array from the function
This article will help us learn how to return an array from the function in haskell using user-defined function along with list comprehension and recursion. In the first example, we are going to use (show (getArray)) function and in the second example, we are going to use (getArray n = [x | x [Int] getArray n = [x | x Int) -> [Int] -> [Int] getArray f xs = map f xs main :: IO () main = do putStrLn (show (getArray (*2) [1, 2, 3, 4, 5])) Output [2, 4, 6, 8, ...
Read MoreHaskell Program to pass an array to the function
In Haskell, we will pass an array to the function by using user-defined functions. In all the examples, we are going to pass an array to the user-defined functions to perform the certain tasks. These functions can be sumArray, maxArray, minArray, countEvens, etc. In this method, the user-defined functions are created that will contain the function definition with some returning value and is being called by passing an array as argument to it. Algorithm Step 1 − The user defined function is defined by writing its definition with a return value. Step 2 − Program execution will ...
Read MoreHaskell Program to create a function with arguments and a return value
In this article, we are going to understand how to create a function with argument and a return value in Haskell using a user-defined function. The user-defined functions are defined that will contain the function definition with some returning value and is being called by passing desired arguments to it. These functions perform various operations as per the definition. In all the examples, we are going to define user-defined functions to perform certain tasks that will return some value and are passed with some arguments like, add, mult, maxOfTwo and other functions. Algorithm Step 1 − The user ...
Read More