Server Side Programming Articles - Page 267 of 2650

Haskell Program to Check Leap Year

Akhil Sharma
Updated on 25-Apr-2023 15:34:14

791 Views

In Haskell, we can check whether a given year is a leap year is not using simple boolean expression. A leap year is a year that has an extra day (February 29th) compared to a normal year. For example, 2004 is a leap year. To determine if a year is a leap year or not, there are a few rules that must be followed. Algorithm Step 1 − The isLeapYear function is defined Step 2 − Program execution will be started from main function. The main() function has whole control of the program. It is written as main ... Read More

Haskell Program to Convert Array to Set (HashSet)

Akhil Sharma
Updated on 25-Apr-2023 15:26:36

282 Views

In Haskell, we will convert Array to Set (HashSet) by using fromList, nub and foldr functions. In the first example, we are going to use ( let set = Set.fromList arr) and in the second example, we are going to use ( let set = nub arr). And in the third example, we are going to use (let set = foldr Set.insert Set.empty arr). Algorithm Step 1 − The Data.Set module is imported to work over set. Step 2 − The program execution will be started from main function. The main() function has whole control of the ... Read More

Haskell Program to Convert File to Byte Array

Akhil Sharma
Updated on 25-Apr-2023 15:25:46

489 Views

In Haskell, we will convert File to byte array by using B.readFile function along with fromIntegral and foldl function. In the first example, we are going to use ( let byteArray = B.unpack bytes) and in the second example, we are going to use (let wordArray = map fromIntegral (B.unpack bytes) :: [Word8]). And in the third example, we are going to use (let byteArray = B.foldl' (\acc byte -> acc ++ [byte]) [] bytes). Algorithm Step 1 − The Data.ByteString modules are imported. Step 2 − The program execution will be started from main function. The main() ... Read More

Haskell Program to convert primitive types to objects

Akhil Sharma
Updated on 25-Apr-2023 15:12:55

200 Views

In Haskell, we will convert primitive types to objects by using accessor functions along with getName function, constructors and record syntax. In the first example, we are going to use (getName person = name person) and in the second example, we are going to use (getName (Person name _) = name and getAge (Person _ age) = age). And in the third example, we are going to use record syntax. Algorithm Step 1 − The ‘Person’ data type is defined with two fields I.e., Name and Age. Step 2 − The getName function is defined Step 3 − ... Read More

Multiple Interfaces in Golang

Sabid Ansari
Updated on 25-Apr-2023 11:30:49

2K+ Views

Interfaces in Golang are an integral part of the language's design philosophy. They enable polymorphism, which is the ability to create objects with different underlying types but with common behavior. However, sometimes a struct needs to implement multiple interfaces. This is where multiple interfaces come into play. In this article, we'll explore the concept of multiple interfaces in Golang, how to implement them, and their practical applications. What are Multiple Interfaces in Golang? In Golang, a type can implement multiple interfaces. When a struct implements multiple interfaces, it gains access to all the methods of those interfaces. This means that ... Read More

Multiple Goroutines

Sabid Ansari
Updated on 25-Apr-2023 11:28:59

300 Views

In computer programming, goroutines are lightweight threads that allow for concurrent execution of code in a single process. Goroutines are a key feature of the Go programming language, which was developed by Google in 2009. In this article, we'll explore the concept of multiple goroutines and how they can be used to improve the performance of your applications. What is a Goroutine? A goroutine is a function that is executed concurrently with other goroutines in a single Go process. Goroutines are similar to threads, but they are much lighter and more efficient. When a goroutine is created, it is assigned ... Read More

Methods With Same Name in Golang

Sabid Ansari
Updated on 25-Apr-2023 11:26:50

838 Views

Go programming language allows multiple methods with the same name, as long as they are defined on different types. This feature is known as method overloading. In this article, we will discuss how to implement methods with the same name in Go and their usage. What are Methods in Golang? Methods in Go are functions that are associated with a specific type. They allow us to define behavior for a particular type. Methods can be defined on both user-defined types and built-in types. Syntax of Methods in Go func (t Type) methodName(parameterList) (returnType) { // Method body ... Read More

Methods in Golang

Sabid Ansari
Updated on 25-Apr-2023 11:25:39

2K+ Views

In Go, methods are functions that are associated with a specific type. They allow developers to define behavior for objects of that type. In this article, we will explore the basics of methods in Go, how to define and use them, and the different types of methods available. Defining Methods in Golang In Go, methods are defined by associating them with a type using the following syntax − func (receiver type) methodName(parameters) returnType { // method body } The "receiver" is the type that the method is associated with. It can be a value or a ... Read More

Matching using regexp in GoLang

Sabid Ansari
Updated on 25-Apr-2023 11:24:23

344 Views

Matching using regular expressions, or regex, is a common task in programming. Go, also known as Golang, provides a built-in package called "regexp" that allows developers to use regular expressions in their programs. In this article, we will explore how to use regular expressions in Go and the different functions and methods available in the "regexp" package. What is Regular Expression? A regular expression, or regex, is a sequence of characters that define a search pattern. Regular expressions are used to search, replace, and manipulate text. They are a powerful tool for text processing and data validation. Using Regexp in ... Read More

Loop Control Statements in Go Language

Sabid Ansari
Updated on 25-Apr-2023 11:22:02

538 Views

Loop control statements are used in programming languages to control the flow of loops. These statements help developers to execute certain conditions during loop execution. Go, also known as Golang, is a popular open-source programming language that provides three loop control statements: break, continue, and goto. In this article, we will explore each of these statements in detail and their usage in Go. The Break Statement The break statement is used to terminate a loop prematurely. It is usually used when a specific condition is met, and there is no need to continue iterating. The following example shows the usage ... Read More

Advertisements