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 10 of 13
Haskell program to multiply two floating point numbers
This tutorial will help us in multiplying two floating point numbers. The multiplication is simply an arithmetic mathematical operation. In Haskell, floating point numbers are represented as values of the Float or Double type. You can use the (*) operator or the multiply() function to multiply two floating point numbers in Haskell. Alternatively, we can also use (/) operator to multiply two floating point numbers by dividing 1 by the reciprocal of the second number. Method 1: Using Multiply Function This method uses multiply() function to multiply two floating point numbers. The function is defined before the main function, as ...
Read MoreHaskell Program to calculate the area of Cube
This tutorial will help us in calculating the area of a cube. There are various approaches to calculating the area but the mathematical formula to calculate the area will remain the same I.e., 6*(side^2). Method 1: Using cubeArea Function This example defines a function cubeArea that takes a single argument, the length of the cube's sides, and returns the area of the cube. The main function calls the cubeArea function to calculate the area. The result is then printed to the console. Algorithm Step 1 − The function cubeArea is being defined on the basis of simple mathematical formula ...
Read MoreHaskell Program to check whether a variable is defined or not
This tutorial will help us in checking whether a variable is defined or not. In Haskell, a variable is considered defined if it has a value assigned to it. The value can be of any type, including a special type called Maybe that is used to represent values that may or may not be present. Algorithm Step 1 − The Data.Maybe module is imported. Step 2 − The checkDefined function is defined as, checkDefined x = isJust x. It takes a Maybe value and returns a Bool indicating whether the value is Just (i.e. defined) or Nothing (i.e. not ...
Read MoreHaskell Program to Check the birthday and print Happy Birthday message
In Haskell, this program will help us in checking the current date against a specified birthday and prints a "Happy Birthday" message if it is a match otherwise, it will print “Not your birthday yet”. Haskell provides function to fetch the current date and also to specify a date. This program can be implemented by using various approaches including the use of toGregorian function, fromGregorian function or by using utctDay getCurrentTime. This program will only check the birthday once, when the program runs. If we want the program to check the birthday periodically or at a specific time, we ...
Read MoreHaskell Program to Iterate over enum
In Haskell, an enumeration (or "enum") is a type that has a finite set of values. The values are called constructors, and are usually defined using the data keyword. Here's an example of an enumeration type that represents the four seasons − data Season = Spring | Summer | Fall | Winter Enumerations are used to represent things like states, modes, or options that have a fixed set of possible values. Method 1: Iterate over enumeration type This method is used to directly iterate over the enumeration type in Haskell. Here, we define the list of all the enumeration ...
Read MoreHaskell Program to Implement multiple inheritance
Haskell is a functional programming language and does not have a concept of inheritance. Instead, it uses type classes to achieve similar functionality. This tutorial will help us in implementing the same in Haskell. Method 1: Implement a type class that simulates multiple inheritances. This method uses type class to simulate the multiple inheritance. Here, we define two parent class and one child class. And the function of child class is being called. Once the function is being called it will take instance from both the parent class and the final output is displayed. Algorithm Step 1 − The ...
Read MoreHaskell Program to initialize and print a complex number
This tutorial will help us in initializing and printing a complex number. In Haskell, the Data.Complex library provides a Complex type to represent complex numbers. Method 1: Using Complex data type This method defines a Complex data type that holds the real and imaginary parts of a complex number, and an instance of the Show type class for Complex, which allows it to be printed using the putStrLn function. In the main function, it creates a complex number object with real part and imaginary part. Then it prints the complex number using the putStrLn function and the show function. Algorithm ...
Read MoreHaskell Program to print Hello World!
This tutorial will discuss writing a program to print Hello World! in Haskell Programming Language. The Computations in Haskell are done using mathematical functions. In this tutorial, We will discuss different ways to print Hello World! in Haskell. Program to print Hello World! Using the “print” function. Program to print Hello World! Using the “putStr” function. Program to print Hello World! Using the “putStrLn” function. Example Program to print Hello World! Using the “print” function main :: IO() main = do -- printing using the function print print ("Hello World!") Output Hello World! ...
Read MoreHaskell Program To Check Whether The Input String Is A Palindrome
This tutorial discusses writing a program to check whether the input string is a palindrome in the Haskell programming language. A string is said to be a palindrome when it results in an exact string after reversing it. For example, the string “level” is a palindrome because it results in an exact string even after reversing it. In this tutorial we see, Program to check whether the string is a palindrome using a built-in function reverse. Program to check whether the string is a palindrome using a recursive function. Method 1: Checking The String Is A Palindrome Using ...
Read MoreHaskell Program To Find The Factorial Of A Positive Number
This tutorial discusses writing a program to find the factorial of a positive number in the Haskell programming language. In this tutorial, we see Program to find the factorial of a positive number using a recursive function. Program to find the factorial of a positive number using an inbuilt function product. Algorithm Steps Take input or initialize a variable to store a positive integer. Implement program logic to find the factorial of a number. Print the resulting factorial. Method: Find The Factorial Of A Positive Number Using A Recursive Function Example Program to find the factorial ...
Read More