Code · 1 file
Sample Haskell File
Haskell is a purely functional, lazily evaluated language with a strong type system. The Haskell sample is a small program — a customer record, a VIP check and a formatted total — that is the same in every language we offer, so you can compare them side by side.
Haskell · 578 B
Sample Haskell file
An idiomatic Haskell example: a customer record type, a VIP check, a total and a formatted loop — the same program in every language we offer.
CC0 · free for any use · Verified by an independent tool · Report a problem
-- Sample Haskell program — samplefiles.com
module Main where
import Text.Printf (printf)
data Customer = Customer { customerId :: Int, name :: String, balance :: Double }
isVip :: Customer -> Bool
isVip c = balance c >= 10000
totalBalance :: [Customer] -> Double
totalBalance = sum . map balance
main :: IO ()
main = do
let customers = [Customer 1 "Ada" 12500, Customer 2 "Grace" 830.5, Customer 3 "Linus" 10000]
mapM_ (\c -> printf "%-6s %10.2f %s\n" (name c) (balance c) (if isVip c then "VIP" else "")) customers
printf "Total: %.2f\n" (totalBalance customers)File details
Download from the command line
curl -L -o Sample.hs https://files.samplefiles.com/code/hs/Sample.hswget https://files.samplefiles.com/code/hs/Sample.hshttps://files.samplefiles.com/code/hs/Sample.hsprintf '%s %s\n' 376e12da3325ba752e538a59ae9c7a6b9388a366e2ca85985b548192d80d829b Sample.hs | shasum -a 256 -cOr check the download in your browser with the checksum calculator.