Tutorial by Examples

A basic "Hello, World!" program in Haskell can be expressed concisely in just one or two lines: main :: IO () main = putStrLn "Hello, World!" The first line is an optional type annotation, indicating that main is a value of type IO (), representing an I/O action which "...
The factorial function is a Haskell "Hello World!" (and for functional programming generally) in the sense that it succinctly demonstrates basic principles of the language. Variation 1 fac :: (Integral a) => a -> a fac n = product [1..n] Live demo Integral is the class of in...
Lazy evaluation means Haskell will evaluate only list items whose values are needed. The basic recursive definition is: f (0) <- 0 f (1) <- 1 f (n) <- f (n-1) + f (n-2) If evaluated directly, it will be very slow. But, imagine we have a list that records all the results, fibs ...
Online REPL The easiest way to get started writing Haskell is probably by going to the Haskell website or Try Haskell and use the online REPL (read-eval-print-loop) on the home page. The online REPL supports most basic functionality and even some IO. There is also a basic tutorial available which c...
A few most salient variants: Below 100 import Data.List ( (\\) ) ps100 = ((([2..100] \\ [4,6..100]) \\ [6,9..100]) \\ [10,15..100]) \\ [14,21..100] -- = (((2:[3,5..100]) \\ [9,15..100]) \\ [25,35..100]) \\ [49,63..100] -- = (2:[3,5..100]) \\ ([9,15..100] ++ [25,35..100] ++ [49,63..1...
We can declare a series of expressions in the REPL like this: Prelude> let x = 5 Prelude> let y = 2 * 5 + x Prelude> let result = y * 10 Prelude> x 5 Prelude> y 15 Prelude> result 150 To declare the same values in a file we write the following: -- demo.hs module De...

Page 1 of 1