Haskell
v9.0.1
Haskell
v9.0.1
Haskell is a statically typed, purely functional programming language named after logician Haskell Curry, first standardized in 1990 by an international committee. It features lazy evaluation, strong static typing with type inference, immutability by default, and a powerful type system including type classes and monads for managing effects.
Haskell is used in academia, research, and increasingly in industry for domains where correctness and reliability matter, such as compilers, financial systems, and concurrent applications. Its emphasis on pure functions and expressive types helps catch errors at compile time. The Glasgow Haskell Compiler (GHC) is the de facto standard implementation.
main :: IO ()
main = putStrLn "Hello, World!"main :: IO ()
main = do
putStr "Enter your name: "
name <- getLine
putStrLn ("Hello, " ++ name ++ "!")import Control.Monad (forM_)
main :: IO ()
main = do
let fruits = ["apple", "banana", "cherry"]
forM_ (zip [1..] fruits) $ \(i, fruit) ->
putStrLn (show i ++ ": " ++ fruit)factorial :: Integer -> Integer
factorial n = if n <= 1 then 1 else n * factorial (n - 1)
main :: IO ()
main = print (factorial 5)fib :: Int -> Int
fib 0 = 0
fib 1 = 1
fib n = fib (n - 1) + fib (n - 2)
main :: IO ()
main = print (map fib [0..9])main :: IO ()
main = do
let nums = [1..10]
print (map (*2) nums)
print (filter even nums)
print (foldr (+) 0 nums)data Shape = Circle Double | Rect Double Double
area :: Shape -> Double
area (Circle r) = pi * r * r
area (Rect w h) = w * h
main :: IO ()
main = do
print (area (Circle 2.0))
print (area (Rect 3.0 4.0))safeDiv :: Int -> Int -> Maybe Int
safeDiv _ 0 = Nothing
safeDiv a b = Just (a `div` b)
main :: IO ()
main = do
print (safeDiv 10 2)
print (safeDiv 10 0)data Person = Person { name :: String, age :: Int }
category :: Person -> String
category p
| age p < 18 = "minor"
| age p < 65 = "adult"
| otherwise = "senior"
main :: IO ()
main = do
let p = Person { name = "Alice", age = 30 }
putStrLn (name p ++ ": " ++ category p)class Describable a where
describe :: a -> String
data Dog = Dog
data Cat = Cat
instance Describable Dog where
describe _ = "a dog"
instance Describable Cat where
describe _ = "a cat"
main :: IO ()
main = do
putStrLn (describe Dog)
putStrLn (describe Cat)Yes. CompileBytes compiles and runs your Haskell code in the browser with no need to install GHC locally.
This compiler runs GHC 9.0.1 (the Glasgow Haskell Compiler), so language extensions and base library features available up to that release are supported.
Use getLine within an IO do-block to read a line from standard input. Enter your text in the input/stdin panel before running.
Yes, running Haskell on CompileBytes is completely free and requires no signup.
In Haskell, all side effects like printing happen in the IO monad, so an executable program must define main :: IO () as its entry point.