haskell lecture 1

Download Haskell Lecture 1

Post on 25-Dec-2014

1.282 views

Category:

Technology

1 download

Embed Size (px)

DESCRIPTION

Haskell講義第1回

TRANSCRIPT

  • 1. Haskell Lecture 1 kinokkory@shiatsumat
  • 2. Haskell
  • 3. Haskell PLUS Pure Lazy Useful Simple
  • 4. HaskellEsolang Haskell Haskell
  • 5. Pure pure functional language referential transparency
  • 6. Lazy lazy evaluation call by need
  • 7. Useful C
  • 8. Simple
  • 9. Haskell
  • 10. Haskell Platform Haskell Platform GHC (), GHCi (), Cabal (), Haddock ( ),
  • 11. VimEmacs () IDE IDE
  • 12. ghc *.hs ghci cabal install *
  • 13. Haskell
  • 14. BNF
  • 15.
  • 16. [pattern] {pattern} 0 {pattern}+ 1 (pattern) pattern1 | pattern2 pattern ... [a..zA..Z]
  • 17.
  • 18. Mainmain Mainmain
  • 19. Main (Main)
  • 20. public private / public
  • 21. public
  • 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
  • 23. export qvar | qtycon | qtycon (..) | qtycon (cname1, ...) | qtycls | qtycls (..) | qtycls (qvar1, ...) | module modid
  • 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
  • 25. topdecl typedecl | datadecl | newtypedecl | classdecl | instdecl | defaultdecl | decl decl vardecl | sigdecl | fixitydecl
  • 26. Haskell type-safe static typing
  • 27. C++ C++ Haskell polymorphic type parametric polymorphism ad-hoc polymorphism
  • 28. Int, Integer, Float, Double, ... Char ([Char]) [a] () (a,b,c) a->b
  • 29. 22 f :: (a,b)->c x :: a, y :: b f (x,y) :: c f :: a->b->c x :: a, y :: b f x y :: c Haskell212 f x a->b->c = a->(b->c) f x y = (f x) y currying partial application
  • 30. Haskell type inference main type
  • 31. type btype [-> 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]}
  • 32.
  • 33. C C algebraic data type
  • 34. 2 C++ data constructor data constructor
  • 35. Haskell
  • 36.
  • 37. C++ Read () Show ()Num ()Ord ()Functor ()Monad () type class
  • 38. (Eq, Ord, Enum, Bounded, Show, Read ) deriving
  • 39. /
  • 40. Ctypdef
  • 41. Int {-#UNPACK#-}
  • 42. newtype
  • 43. datadecl data [context =>] 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 | :})
  • 44. newtypedecl newtype [context =>] 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
  • 45. classdecl class [scontext =>] tycls tyvar where {cdecl1; ...} class qtycls tyvar | qtycls (tyvar atype1 ... atypen) context class | (class1, ..., classn) simpleclass qtycls tyva

Recommended

View more >