1 / 10

600.429 FUNCTIONAL PROGRAMING AT WORK - HASKELL AND DOMAIN SPECIFIC LANGUAGES

600.429 FUNCTIONAL PROGRAMING AT WORK - HASKELL AND DOMAIN SPECIFIC LANGUAGES. Dr. John Peterson Western State Colorado University. Quiz. Why would we be interested in a pure language? What is a type in which each constructor has no arguments like? Example?

lorin
Download Presentation

600.429 FUNCTIONAL PROGRAMING AT WORK - HASKELL AND DOMAIN SPECIFIC LANGUAGES

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 600.429FUNCTIONAL PROGRAMING AT WORK - HASKELL AND DOMAIN SPECIFIC LANGUAGES Dr. John Peterson Western State Colorado University

  2. Quiz • Why would we be interested in a pure language? • What is a type in which each constructor has no arguments like? Example? • What is the meaning of the type (a -> Maybe b) -> [a] -> [b]? • Why does Haskell lack control flow constructs?

  3. Quiz • zipWith (+) [1, 2, 3] [3, 1] • map (*2) [1..4] • map ((* 3) . (- 1)) [2, 3]

  4. Old Homework • http://wiki.western.edu/mcis/index.php/429/Week_1

  5. New Homework • Let’s talk BlackJack • What sort of state would this need? • Where would the random numbers be used? • How can we shuffle the deck functionally? • How would the dealer strategy be encoded? • How would you track your winnings over multiple games?

  6. New Homework • Any questions? • Let’s give the user three tries instead of one.

  7. IO in Haskell • Does the word “Monad” scare you? • Why is there IO in the type of main? • What is the purpose of the IO type? • Is monadic programming significantly different from ordinary imperative programming?

  8. The IO Monad Bottom line: IO tags functions that interact with the outside world IO cannot be “removed” from a type The () type is like void in C – it’s a type you use when there’s no value of interest. Some IO primitives: putStr :: String -> IO () getLine :: IO String

  9. Using do notation The do notation provides a way to make the underlying monadic operators more readable. do op -- execute in the monad without resultvar <- op -- execute and bind return val -- return value (empty computation)

  10. Reading from Strings type ReadS a = String -> [(a,String)] reads :: (Read a) => ReadS a

More Related