Akhil Sharma has Published 671 Articles

Golang program to add two dates

Akhil Sharma

Akhil Sharma

Updated on 03-Apr-2023 12:49:14

427 Views

In this Golang article, we will write programs to add two dates. The dates are added using methods like Add(), AddDate(). There are different formats to represent a date. Here, the dates after addition will be represented using YY/MM/DD format. Syntax func (t Time) Sub(u Time) Duration The sub() ... Read More

Haskell Program to Convert String value to byte Value

Akhil Sharma

Akhil Sharma

Updated on 28-Mar-2023 15:21:13

364 Views

In Haskell, we will convert String Value to Byte value by using ord , B.pack and fromNum functions. In the first example, we are going to use (stringToBytes = map ord ) function and in the second example, we are going to call (stringToBytes = B.pack) function. And in the ... Read More

Haskell Program to Convert Set of String to Array of String

Akhil Sharma

Akhil Sharma

Updated on 28-Mar-2023 15:00:44

260 Views

In Haskell, We can use listArray and toList functions as well as list comprehension to convert set of string to array of string. In the first example, we are going to use (setToArray set = listArray (1, Set.size set) (Set.toList set)) function and in the second example, we are going ... Read More

Haskell Program to Convert List to Set

Akhil Sharma

Akhil Sharma

Updated on 28-Mar-2023 14:59:18

833 Views

Haskell programming has internal functions like fromList, Set.fromList and foldr functions that can be used to convert list to set. In the first example, we are going to use (listToSet = Set.fromList) function and in the second example, we are going to call (set = Set.fromList xs) function directly from ... Read More

Haskell Program to Convert List to a Map

Akhil Sharma

Akhil Sharma

Updated on 28-Mar-2023 14:57:54

731 Views

In Haskell, we will convert List to a Map by using fromList and foldl functions. This can also be done using recursion and pattern matching. In the first example, we are going to use (listToMap xs = Map.fromList xs) function and in the second example, we are going to use ... Read More

Haskell Program to Convert String to an Array

Akhil Sharma

Akhil Sharma

Updated on 28-Mar-2023 14:56:48

1K+ Views

In Haskell, we will convert String to an Array by using listArray and intersperse functions. In the first example, we are going to use (stringToArray s = listArray (0, length s - 1) s) function and in the second example, we are going to use (stringToArray s = s) function. ... Read More

Haskell Program to Convert Character to String

Akhil Sharma

Akhil Sharma

Updated on 28-Mar-2023 14:55:14

2K+ Views

In Haskell, we can convert Character to String by using user-defined function, show function, list comprehension and (:[]) notation. In the first example, we are going to use (charToString c = [c]) function and in the second example, we are going to use (charToString c = show c) function. Where ... Read More

Haskell Program to Convert Data to Hexadecimal

Akhil Sharma

Akhil Sharma

Updated on 28-Mar-2023 14:51:47

719 Views

In Haskell, we will convert Data to Hexadecimal by using intToDigit, toHex and showHex functions. In the first example, we are going to use toHex function and (stringToHex = concatMap (\c -> toHex (fromEnum c))) function and in the second example, we are going to use convertToHex x = showHex ... Read More

Haskell Program to Print Inverted Star Pattern

Akhil Sharma

Akhil Sharma

Updated on 28-Mar-2023 14:36:40

328 Views

In Haskell, to print Inverted star pattern we will be using mapM_, reverse, unlines and replicate functions. In the first example, we are going to use ( invertedStarPattern n = mapM_ putStrLn (reverse [replicate i '*' | i

Haskell Program to Print Diamond Star Pattern

Akhil Sharma

Akhil Sharma

Updated on 28-Mar-2023 14:34:57

231 Views

In Haskell, to print Diamond star pattern we will be using mapM_, reverse, unlines and replicate functions. In the first example, we are going to use ( diamondStarPattern n = unlines $ topHalf ++ bottomHalf where topHalf = [replicate (n - i) ' ' ++ replicate ((2 * i) - 1) '*' | i

Advertisements