Haskell语言的概览性介绍,内容有: 若干语言特性(是什么让Haskell如此独特?):Lambda,Curry, Algebraic Data Type,Type Class, Purity,Lazy Evaluation; 对并行与并发的支持; 若干有启发性的例子以及性能问题; Haskell在工业界的应用;
2.
- A language that doesnt effect how you think about programming
is not worth learning
Alan Perlis 3.
-
- Algebraic Data Type Type Class
4. (Programming Paradigm)
5.
6. 7. Functional Programming
- FP (evaluation) (mutable) FP (application)
8.
9. Lambda
10. First-Class Function & High Order Function
11. Currying(Partial Application)&High Order
12. - 3D
13. Example -FieldTrip
http://www.haskell.org/haskellwiki/FieldTrip
14. Example -FieldTrip
- revolve :: Curve2 -> ParamSurf
- torus :: R -> R -> ParamSurf
- torus sr cr = revolve (const (sr,0) ^+^ const cr *^
circle)
- sphere = revolve semiCircle
15. Example - 3D
16. Algebraic Data Type
Constructor Constructor 17. Algebraic Data Type
18. Pattern Matching
- Node (Leaf 4) (Node Empty (Leaf 5))
- accum (Node left right) = (accum left) + (accum right)
19.
20. Type Classes
- elem :: Eq a => a->[a]->Bool
OO class 21. Instance of Type Classes
- instanceEq (Maybe a) where
- Just v1 == Just v2 = v1 == v2
- Nothing == Nothing = True
22. Lazy Evaluation
- a = [1..] -- infinite list
23. Purity
24. Purity
25. Purity
26. Referential Transparent
- f(5) + f(5); // 15 + 16 = 31
27.
28. IO Action
- IO () IO first-class IO IO main IO
--putStrLn :: String -> IO () --main :: IO () main = putStrLn
"Hi Haskell!" 29. Monad
- Haskell Monad Monad "warm fuzzy thing" ( )!
-
- --Simon Peyton Jones Haskell
30. Monad
- bind:: m a -> (a -> m b) -> m b
Monad m a bind inject a (a -> m b) 31. Example -
32. Example - , Hommage Haskell Offline Music Manipulation And
Generation EDSL
http://substitut-fuer-feinmotorik.net/projects/haskellommage
33.
34.
- forkIO :: IO () -> IO ThreadId
- forkIO (writeFile "temp.txt" "haskell thread")
35. Shared Mutable State Concurrency
- Race conditions due to forgotten locks
- Deadlocks resulting from inconsistent lock ordering
- Corruption caused by uncaught exceptions
- Lost wakeups induced by omitted notifications
36. Software Transactional Memory(STM)
37. STM Sample
- import Control.Concurrent.STM
- transfer::Float->Bal->Bal->STM ()
- transfer qty fromBal toBal = do
- catchSTM :: STM a -> (exception->STM a) -> STM a
- complexAction = action1 `orElse` action2
- main = atomically complexAction
40.
- sort :: (Ord a) => [a] -> [a]
- sort (x:xs) = lesser ++ x:greater
- where lesser = sort [y | y [a] -> [a]
- parSort (x:xs) =forcegreater`par`
- ( forcelesser`pseq`(lesser ++ x:greater))
- where lesser = parSort [y | y (a -> b) -- map function
- -> Strategy c -- evaluation strategy for reduction
- -> ([b] -> c) -- reduce function
- -> [a] -- list to map over
- mapReduce mapStrat mapFunc reduceStrat reduceFunc input
- = mapResult `pseq` reduceResult
- where mapResult = parMap mapStrat mapFunc input
- reduceResult = reduceFunc mapResult `using` reduceStrat
45.
- GPipe EDSL GPU , Haskell GPU Haskell OpenGL GLSL
46. Example - GPU
- http://www.haskell.org/haskellwiki/GPipe
47. Parser Combinator
- ( Lex Yacc Flex Bison Antlr) parse
- Haskell parser Parser Combinator
48. Example - Parser Combinator for JavaScript
- parser combinator ( )parser
-
- repeat1(alternate(sequence(parser1, parser2), parser3))
49. EDSL
50.
- TheComputerLanguageBenchmarksGame
-
- http://shootout.alioth.debian.org/
-
-
http://blog.csdn.net/soloist/archive/2009/04/09/4060081.aspx
51. 52. 53.
- FP Scala Haskell Java JVM
54.
- http://blog.csdn.net/soloist
55.