Parallel and Concurrent Haskell 

2016

1-1: Introduction

Everything in Haskell is PURE (function), including side effects (print, I/O such as open files, update data, …)

“Pure”: f (x) = a, regardless of ‘x’ value may change, always returns the result ‘a’

https://youtu.be/N6sOMGYsvFA

2.1 Function

f a b = function f, arg a & b

sqDist (x, y ) = x^2 + y^2
main = print $ sqDist (3, 4)
dist pt  = sqrt  $ sqDist pt

dist = sqrt . sqDist

Note: pronounce “.” as “AFTER

id  :: a -> a [Signature] # Polymorphic
id  x = x [Implementation]

flop :: (a, b) -> (b, a)
flop p = = (snd p,fst p)

flop’ (x,y) = (y,x)

Example:
print $ flop (5, “Hello!”)

Currying 
sqDist :: Double ->Double -> Double
Equivalent to: sqDist 1 arg but return a function (Double -> Double)
sqDist :: Double -> (Double -> Double)

sqDist x y = x^2 + y^2

Equiv: sqDist (x,y) # but difficult to partial application.

Partial Application (pass fewer args)
sqDist 0 = Double -> Double


sqdistfromzero
:: Double -> Double

sqdistfromzero
= sqDist 0

Parallel and Concurrent Haskell: http://www.youtube.com/playlist?list=PLbgaMIhjbmEm_51-HWv9BQUXcmHYtl4sw

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s