Presentation is loading. Please wait.

Presentation is loading. Please wait.

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

Similar presentations


Presentation on theme: "600.429 FUNCTIONAL PROGRAMING AT WORK - HASKELL AND DOMAIN SPECIFIC LANGUAGES Dr. John Peterson Western State Colorado University."— Presentation transcript:

1 600.429 FUNCTIONAL 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 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 result var <- 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


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

Similar presentations


Ads by Google