Haskell Lecture 1

Download Haskell Lecture 1

Post on 25-Dec-2014

1.276 views

Category:

Technology

1 download

Embed Size (px)

DESCRIPTION

Haskell1

TRANSCRIPT

<ul><li> 1. Haskell Lecture 1 kinokkory@shiatsumat </li> <li> 2. Haskell </li> <li> 3. Haskell PLUS Pure Lazy Useful Simple </li> <li> 4. HaskellEsolang Haskell Haskell </li> <li> 5. Pure pure functional language referential transparency </li> <li> 6. Lazy lazy evaluation call by need </li> <li> 7. Useful C </li> <li> 8. Simple </li> <li> 9. Haskell </li> <li> 10. Haskell Platform Haskell Platform GHC (), GHCi (), Cabal (), Haddock ( ), </li> <li> 11. VimEmacs () IDE IDE </li> <li> 12. ghc *.hs ghci cabal install * </li> <li> 13. Haskell </li> <li> 14. BNF </li> <li> 15. </li> <li> 16. [pattern] {pattern} 0 {pattern}+ 1 (pattern) pattern1 | pattern2 pattern ... [a..zA..Z] </li> <li> 17. </li> <li> 18. Mainmain Mainmain </li> <li> 19. Main (Main) </li> <li> 20. public private / public </li> <li> 21. public </li> <li> 22. module module modid where body | module modid (export1, ...) where body | body modid {modid .} modid modid [A..Z] {[a..zA..Z0..9]} module Main (main) where </li> <li> 23. export qvar | qtycon | qtycon (..) | qtycon (cname1, ...) | qtycls | qtycls (..) | qtycls (qvar1, ...) | module modid </li> <li> 24. body {impdecl}{topdecl} impdecl import modid [impspec] | import modid as modid [impspec] | import qualified modid [impspec] | import qualified modid as modid [impspec] impspec (import1, ...) | hiding (import1, ...) import var | tycon [(..) | (cname1, ...)] | tycls [(..) | (var1, ...)] qualified </li> <li> 25. topdecl typedecl | datadecl | newtypedecl | classdecl | instdecl | defaultdecl | decl decl vardecl | sigdecl | fixitydecl </li> <li> 26. Haskell type-safe static typing </li> <li> 27. C++ C++ Haskell polymorphic type parametric polymorphism ad-hoc polymorphism </li> <li> 28. Int, Integer, Float, Double, ... Char ([Char]) [a] () (a,b,c) a-&gt;b </li> <li> 29. 22 f :: (a,b)-&gt;c x :: a, y :: b f (x,y) :: c f :: a-&gt;b-&gt;c x :: a, y :: b f x y :: c Haskell212 f x a-&gt;b-&gt;c = a-&gt;(b-&gt;c) f x y = (f x) y currying partial application </li> <li> 30. Haskell type inference main type </li> <li> 31. type btype [-&gt; type] btype {atype}+ atype qtycon | tyvar | () | (type1, ... ,typen) | [type] | (type) simpletype tycon tyvar1 ... tyvarn qtycon [modid .] tycon tycon [A..Z] {[a..zA..Z0..9]} tyvar [a..z] {[a..zA..Z0..9]} </li> <li> 32. </li> <li> 33. C C algebraic data type </li> <li> 34. 2 C++ data constructor data constructor </li> <li> 35. Haskell </li> <li> 36. </li> <li> 37. C++ Read () Show ()Num ()Ord ()Functor ()Monad () type class </li> <li> 38. (Eq, Ord, Enum, Bounded, Show, Read ) deriving </li> <li> 39. / </li> <li> 40. Ctypdef </li> <li> 41. Int {-#UNPACK#-} </li> <li> 42. newtype </li> <li> 43. datadecl data [context =&gt;] simpletype = constr1 | ... [deriving] constr con [!] atype1 ... [!] atypek | (btype | !atype) conop (btype | !atype) | con {var11, ..., var1m :: (type1 | !atype1), ...} deriving deriving qtycls | deriving (qtycls, ...) con conid | (consym) conop consym | `conid` conid [A..Z] {[a..zA..Z0..9]} consym (: {symbol | :})</li> <li> 44. newtypedecl newtype [context =&gt;] simpletype = newconstr [deriving] newconstr con atype | con {var :: type} var varid | (varsym) varid [a..z] {[a..zA..Z0..9]} varsym (symbol {symbol | :}) typedecl type simpletype = type </li> <li> 45. classdecl class [scontext =&gt;] tycls tyvar where {cdecl1; ...} class qtycls tyvar | qtycls (tyvar atype1 ... atypen) context class | (class1, ..., classn) simpleclass qtycls tyvar scontext simpleclass | (simpleclass1,...,simpleclassn) cdecl vardecl | sigdecl | fixitydecl qtycls [modid . ] tycls tycls [A..Z] {[a..zA..Z0..9]} tyvar [a..z] {[a..zA..Z0..9]} </li> <li> 46. instdecl instance [scontext =&gt;] qtycls inst [where {idecl1; ...}] inst qtycon | (qtycon tyvar1 ... tyvarn) | (tyvar1, ..., tyvarn) | [tyvar] | (tyvar1 -&gt; tyvar2) idecl vardecl </li> <li> 47. // ifcasewhile </li> <li> 48. 123 :: (Num a) =&gt; a 1.23 :: (Fractional a) =&gt; a c :: Char abc :: String (=[Char]) </li> <li> 49. </li> <li> 50. a[a] [1,2,3] :: [Int] [1,2,3] = 1 : 2 : 3 : [] ( : ) </li> <li> 51. /case </li> <li> 52. </li> <li> 53. exp exp0 [:: [context =&gt;] type] expi expi+1 [qop(n,i) expi+1] | lexpi | rexpi lexpi (lexpi | expi+1) qop(l,i) expi+1 rexpi expi+1 qop(r,i) (rexpi | expi+1) qop qvarsym | `qvarid` | qconsym | `qconid` qvarsym [modid . ] varsym qvarid [modid . ] varid qconsym [modid . ] consym qconid [modid . ] conid </li> <li> 54. exp10 apat1 ... apatn -&gt; exp | let {decl1; ...} in exp | if exp then exp else exp | case exp of {alt1; ...} | doexp | {aexp}+ alt pat -&gt; exp [where {decl1; ...}] | pat {| exp0 -&gt; exp}+ [where {decl1; ...}] if case do </li> <li> 55. aexp qvar | qcon | literal | (exp) | (exp1, ..., expn) | [exp1, ..., expn] | [exp1 [, exp2] .. [exp3]] | [exp | qual1, ..., qualn] | (expi+1 qop(a,i)) | (lexpi qop(l,i)) | (qop(a,i) expi+1) | (qop(r,i) rexpi) | qcon {qvar1=exp1; ...} | aexp {qvar1=exp1; ...} </li> <li> 56. pat pat0 pati pati+1 [qconop(n,i) pati+1] | lpati | rpati lpati (lpati | pati+1) qconop(l,i) pati+1 rpati pati+1 qconop(r,i) (rapti | pati+1) </li> <li> 57. pat10 apat | gcon apat1 ... apatn apat var | var [@ apat] | qcon {qvar1=pat1, ...} | literal | _ | (pat1, ... , patn) | [pat1, ..., patn] | ~apat | (pat) </li> <li> 58. / / 0 letwhile </li> <li> 59. vardecl (funlhs | pat0) rhs vardecl (funlhs | var) rhs funlhs var {apat}+ | pati+1 varop(a,i) pati+1 | lpati varop(l,i) pati+1 | pati+1 varop(r,i) rpati | (funlhs) {apat}+ rhs = exp [where {decl1; ...}] | {| exp0 = exp}+ [where {decl1; ...}] </li> <li> 60. </li> <li> 61. -- m a a class Monad m where -- x &gt;&gt;= f x f -- (&gt;&gt;=) :: m a -&gt; (a -&gt; m b) -&gt; m b -- return c c return :: a -&gt; m a </li> <li> 62. IOST IO a -&gt; a </li> <li> 63. do do &gt;&gt;= </li> <li> 64. doexp do {stmt1; ...; stmtn; exp} stmt exp | pat b -&gt; c (x%) :: b -&gt; c (%y) :: a -&gt; c (//) </li> <li> 69. begin{code}end{code} TeX .lhs </li> <li> 70....</li></ul>