putStrLn $ "Hi There" ++ ": welcome to my talk"
I'm going to tell you about the Haskell progamming language
Haskell is:
Focus on using functions to express ideas.
To that end, functions are first class citizens and there are higher order functions.
negate 5
map negate [1, 2, 3, 4, 5]
import Data.Char (toUpper)
toUpper 'a'
toUpperS = map toUpper
toUpperS "foobar"
addBang str = str ++ "!"
shout = addBang . toUpperS
shout "haskell is fun"
:t 'a'
:t "Haskell"
:t (.)
:t (+)
:t map
[1..4]
zip [1..] ['a'..'z']
map (+2) [1..5]
But sweetened with sugar!
e.g. list comprehensions
let's get all the sum of each multimple of 3 from 1 to 50 with each multiple of 7 from 1 to 50:
[ x + y | x <- [1..50], y <- [1..50], x `mod` 3 == 0, y `mod` 7 == 0 ]
import Diagrams.Prelude
import Diagrams.Backend.Cairo
demo0 :: Diagram B
demo0 = circle 1 # fc yellow
demo0
demo1 :: Diagram B
demo1 = square 1 # fc blue # lw none `atop` circle 1 # fc yellow
demo1
Okay that's fun, but let's make a diagram based on some computation result
First, we'll get a list of random numbers. n.b. I'm seeding the random number generator myself for convenience.
import System.Random
rlist :: [Double]
rlist = randoms $ mkStdGen 17
And now create a diagram:
rcircles :: Diagram B
rcircles = hcat $ map circle $ take 7 rlist
rcircles