-- Declare a variable
x = 42
-- Declare a constant
y :: Int
y = 10
-- Declare a list
myList = [1, 2, 3]
-- Declare a tuple
myTuple = (1, "hello")
-- Declare a function
add :: Int -> Int -> Int
add x y = x + y
-- Call a function
result = add 3 4
Haskell uses recursion instead of loops.
-- Define a recursive function to iterate over a list
sumList :: [Int] -> Int
sumList [] = 0
sumList (x:xs) = x + sumList xs
-- Define an if-else statement
max :: Int -> Int -> Int
max x y = if x > y then x else y
import System.IO
-- Open a file
main = do
handle <- openFile "file.txt" ReadMode
contents <- hGetContents handle
putStr contents
hClose handle