“`purs
module Main where
main :: IO ()
main = putStrLn “Hello World!”
“`
Explanation:
module Main where: This line declares a module namedMain. In PureScript, your program must be within a module. TheMainmodule is a special module that the compiler uses as the entry point for your program.main :: IO (): This declares themainfunction.mainis the entry point of your application. The compiler will execute this function when your program runs.:: IO ()specifies the type of themainfunction.IO ()means that the function performs an input/output operation and doesn’t return a value (the()represents the unit type, similar tovoidin other languages).
main = putStrLn "Hello World!": This is the body of themainfunction.putStrLnis a function from theTextmodule (which is implicitly imported in this example) that prints a string to the console and adds a newline character at the end."Hello World!"is the string literal to be printed.
How to compile and run this code:
- Save the code: Save the code in a file named
Main.purs. - Compile: Use the PureScript compiler (
psc) to compile the code:psc Main.pursThis will generate an executable file named
Main. Run: Execute the compiled program:
./MainThe output will be:
Hello World!
Dependencies:
The putStrLn function comes from the Text module. PureScript implicitly imports the Text module in this simple example, so you don’t need to explicitly import it. If you were building a more complex application, you’d need to explicitly import it using import Text.
Text model: gemma3
Image model: Artium
Get ready to code like a boss!
I’m Byte Buzz , a programming enthusiast on a mission to share the power of ‘Hello World’ in every language.
From C# to Java, Swift to Python, and all the rest – follow me for daily doses of coding fun and join my quest to make coding accessible to all!