Values in Haskell

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:

  1. We define a main function as the entry point of our program.
  2. String concatenation is done with ++ instead of +.
  3. We use putStrLn for printing strings and print for other types.
  4. Numeric operations are similar to Go.
  5. Boolean operations use && for AND, || for OR, and not for negation.
  6. We use $ 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.