Title here
Summary here
Haskell has various value types including strings, integers, floats, booleans, etc. Here are a few basic examples.
module Main where
main :: IO ()
main = do
-- Strings, which can be concatenated with ++
putStrLn ("has" ++ "kell")
-- Integers and floats
putStrLn $ "1+1 = " ++ show (1 + 1)
putStrLn $ "7.0/3.0 = " ++ show (7.0 / 3.0)
-- Booleans, with boolean operators as you'd expect
print $ True && False
print $ True || False
print $ not True
To run the program, save it as values.hs
and use runhaskell
:
$ runhaskell values.hs
haskell
1+1 = 2
7.0/3.0 = 2.3333333333333335
False
True
False
In this Haskell example:
main
function as the entry point of our program.++
instead of +
.putStrLn
for printing strings and print
for other types.&&
for AND, ||
for OR, and not
for negation.$
to avoid parentheses in some function calls.Haskell is a purely functional language, so the structure is a bit different from imperative languages, but the basic concepts of working with various value types remain similar.