Haskell - PowerPoint PPT Presentation

1 / 20
About This Presentation
Title:

Haskell

Description:

Bird R. Introduction to Functional Programming using Haskell. ... HUGS. GHC. ???????????. ?????? ?????????????? ????? ?????????????? ??. ????????? ??????? ?????????? ... – PowerPoint PPT presentation

Number of Views:175
Avg rating:3.0/5.0
Slides: 21
Provided by: ewg2
Category:
Tags: haskell | hugs

less

Transcript and Presenter's Notes

Title: Haskell


1
???? Haskell
  • ?????

Eugeny L Yakimovitch http//desk.by/ewger
2008
2
??????????
  • Thompson S. Haskell The Craft of Functional
    Programming. 2-nd edition, Addison-Wesley, 1999.
  • Bird R. Introduction to Functional Programming
    using Haskell. 2-nd edition, Prentice Hall Press,
    1998.
  • ?????? ?. ?. ?????????????? ???????????????? ??
    ????? Haskell. ?.??? ?????, 2007
  • Koen Lindstruem Claessen // http//www.cs.chalmers
    .se/Cs/Grundutb/Kurser/funht/index.html,
    2008-02-04
  • ??????

3
??????????
  • ????? ?????? ?????????? ??? ????????
    ???????????????? ??????????
  • HUGS
  • GHC

4
???????????
  • ?????? ?????????????? ????? ?????????????? ??
  • ????????? ??????? ??????????
  • ??????? (?????, ???????????) ????? ??????,
    ?????????? ?? ?????????? ??????????????
    ??????????
  • ?????? ?????????? (?????????????) ?????????
    ???? ??????????? ??????? fS-gtT, ??? S,T
    ????????? ????
  • ???????? ???? ???????????? ????????? ? ??????
    ???????? ????? ???
  • ??????? ?????? ???????? ??????? ??? ?????
    ????????, ??????? ????????? ? ???? ?????????? ?
    ??????????? ?????? ???????
  • ?????? ????????? ??????????? ??? (??. haskell.org)

5
??????????? ??
dynamically typed
pure functions
higher-order functions
statically typed
type inference
real-time
immutable datastructures
polymorphism
overloading
concurrency
high performance
distribution
parameterized types
lazy
virtual machine
Java
reflection
type classes
object oriented
compiler
interpreter
meta-programming
Haskell
unification
C
backtracking
6
??????? ??????
  • ????????? ?????????? ?????????
  • ?????????? ???. ???????? ???????
  • ??????????? ???????????? ????????
  • ?????????????? ?????????? ???????????? ?????
    ?????????
  • ?????????????? ???????? ?????????
  • ????????????? ????????????? ????????

7
???????? ? ?????????
  • ???????? ????????????? ????? ???????? ????????
  • ????????? ?????????? ? ?????????? ??????????
    (??????????) ??????? ? ????????? (??. ??????
    ??????????). ?????????? (????????) ????????????
    ?? ????????? ????????.
  • Preludegt 'c'
  • 'c' Char
  • Preludegt 3
  • 3 Integer
  • Preludegt not True
  • False Bool
  • Preludegt 5gt7
  • False Bool
  • Preludegt 12
  • 3 Integer

8
???????? ?????????
  • ???????? ????????? ???????? ??????????
    ??????????, ? ?? ???????? ?????? ????????????
    ???????? ??????????? (?.?. ??? ?? ??????????
    ????????? ? ?????????? ??????????)

Preludegt if 2gt3 then 4 else 5 5 Integer
Preludegt if if 1lt2 then 3lt2 else 4lt5 then 'a'
else 'b' ?
9
?????? ?????????
  • ??? ?????? ?????? ????????? ? ???????? ???????
    ????????? ?????? ???????????? ????????? ????? \
  • ? ???????? ????? ??????????????????
  • -gt

gt (\x -gt \y -gt x y) 1 2 3
10
??????? ? ??????
  • module IntroExample
  • (someFunction)
  • Where
  • someFunction Int -gt Int -gt Int
  • someFunction n
  • someFunction n (xxs) (x n) someFunction n
    xs
  • -- n - ?????, ??????? ?????????? ?????????
    ? ??????? ???????? ??????.

11
?????????? ?????
  • module TypeInference
  • (Zero, Succ, One, Two, Three, Four, zero, one,
    two, three, four, Add, Mul, Fac)
  • where

???????? http//www.willamette.edu/fruehr/haskel
l/evolution.html
12
  • --------------------------------------------------
    -----------------------------
  • -- ?????????????? ???, ?????????????? ???????? 0.
  • data Zero
  • --------------------------------------------------
    -----------------------------
  • -- ?????????????? ???, ?????????????? ?????????
    ???????? ?? ???????? ?????.
  • data Succ n

13
  • --------------------------------------------------
    ------------------------------
  • -- ???????? ????? ??? ????????????? ????? ?? 1 ??
    4 (??? ???????). ???????????
  • -- ????????????? ????? ?? ??????????? ?????.
  • type One Succ Zero
  • type Two Succ One
  • type Three Succ Two
  • type Four Succ Three
  • --------------------------------------------------
    ------------------------------
  • -- ??????? ??? ????????????? ????????????? ?????
    ?? 1 ?? 4 (??? ???????).
  • zero undefined Zero
  • one undefined One
  • two undefined Two
  • three undefined Three
  • four undefined Four

14
  • --------------------------------------------------
    ------------------------------
  • -- ????? ??? ????????????? ???????? ???????? (?
    ????????? ?????? ?????).
  • class Add a b c a b -gt c where
  • add a -gt b -gt c
  • --------------------------------------------------
    ------------------------------
  • -- ?????????? ?????? Add ??? ?????????????
    ???????? ????????.
  • instance Add Zero b b
  • instance Add a b c gt Add (Succ a) b (Succ c)

15
  • --------------------------------------------------
    ------------------------------
  • -- ????? ??? ????????????? ???????? ????????? (?
    ????????? ?????? ?????).
  • class Mul a b c a b -gt c where
  • mul a -gt b -gt c
  • --------------------------------------------------
    ------------------------------
  • -- ?????????? ?????? Mul ??? ?????????????
    ???????? ?????????.
  • instance Mul Zero b
    Zero
  • instance (Mul a b c, Add b c d) gt Mul (Succ a) b
    d

16
  • --------------------------------------------------
    ------------------------------
  • -- ????? ??? ????????????? ???????? ??????????
    ?????????? (? ????????? ??????
  • -- ?????).
  • class Fac a b a -gt b where
  • fac a -gt b
  • --------------------------------------------------
    ------------------------------
  • -- ?????????? ?????? Fac ??? ?????????????
    ???????? ?????????? ??????????.
  • instance Fac Zero
    One
  • instance (Fac n k, Mul (Succ n) k m) gt Fac (Succ
    n) m

17
????-?????
  • Writes baz to the file called foo.
  • No result displayedwonder why not?

Preludegt writeFile "foo" "baz" Preludegt
18
?????? ?????-??????
  • module Main
  • where
  • import IO
  • main do hSetBuffering stdin LineBuffering
  • doLoop

19
  • doLoop do putStrLn "Enter a command rFN wFN or
    q to quit"
  • command lt- getLine
  • case command of
  • 'q'_ -gt return ()
  • 'r'filename -gt do putStrLn
    ("Reading " filename)
  • doRead filename
  • doLoop
  • 'w'filename -gt do putStrLn
    ("Writing " filename)
  • doWrite filename
  • doLoop
  • _ -gt doLoop

20
  • doRead filename bracket (openFile filename
    ReadMode)
  • hClose
  • (\h -gt do contents lt-
    hGetContents h
  • putStrLn "The
    first 100 chars"
  • putStrLn
    (take 100 contents))
  • doWrite filename do putStrLn "Enter text to go
    into the file"
  • contents lt- getLine
  • bracket (openFile filename
    WriteMode) hClose
  • (\h -gt hPutStrLn h
    contents)
Write a Comment
User Comments (0)
About PowerShow.com