unit in haskell

Unit in Haskell

In Haskell, the unit type is denoted by (). It is a type that has only one value, also called (). The unit type is often used when a function doesn't need to return any meaningful value, but still needs to be executed for its side effects.

Here's an example of a function that takes no arguments and returns the unit type:

helloWorld :: () -> ()
helloWorld () = putStrLn "Hello, World!"

In this example, the function helloWorld takes a value of type () as an argument and returns a value of type (). The function doesn't do anything with the argument, but it prints "Hello, World!" to the console using the putStrLn function.

You can call this function by passing the unit value () as an argument:

main :: IO ()
main = helloWorld ()

When you run the program, it will print "Hello, World!" to the console.

I hope this answers your question! Let me know if you need further assistance.