1 / 16

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. Coming Up. Nov 26: Haskell Extensions Nov 28: Work Day Dec 3: Presentation #2 Dec 4: Paul Hudak’s talk @ 10:45

ganesa
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. Coming Up • Nov 26: Haskell Extensions • Nov 28: Work Day • Dec 3: Presentation #2 • Dec 4: Paul Hudak’s talk @ 10:45 • Dec 5: Presentation #2, Final turnin requirements, work day • Dec 13: Department seminar on reactive programming @ 10:45 • Dec 13: Final exam – detailed presentations

  3. Presentation #2 This presentation will consist of a demo + a code presentation. Show us how you’re using Haskell. This will be an individual effort. Your presentation should be about 6 minutes and demonstrate something useful that you are using in your project. Presentation order will be posted soon!

  4. Presentation 2 Topics • How to use Haskell to solve specific problems you have in your system • Haskell libraries of general interest • Features of Haskell that we haven’t covered (includes non-standard language extensions)

  5. Your Presentation • Explain what problem you want to solve • Show and run code that deals with this problem – comment the code as needed • Create a wiki page with your presentation in it that will help others understand your code – use this are your slides • Take questions and be able to edit your demos

  6. Type Families We have been working with single parameter type classes: Eq, Ord, Num, … What about operators that need to vary more than one type? (==) :: Eq a => a -> a -> Bool (+) :: Num a => a -> a -> a You can use two different type classes at once: foo :: (Num a, Eq b) => a -> a -> b But what if a and b are somehow related?

  7. Type Families Recall our reactive engine: we defined > as (>*) :: Ord a => Behavior a -> Behavior a -> Behavior Bool. Why couldn’t we just use > instead? Note that you can use the module system to hide the “bad” version of > and redefine it for behaviors – what’s wrong with this?

  8. A Different Ord Class class Ordable a where type Res a -- New stuff! (>) :: a -> a –> Res a The type synonym here is new – it defines a type which is local to a particular instance of Ordable instead of general to the program. This is a type synonym – it just gives a new name to an existing type

  9. An Ord Instance instance OrdableInt where type Res Int = Bool (>) = (Prelude.>) This says that when comparing Int value, the result will be a boolean. Note that I needed to refer to the old definition of >.

  10. Behavioral Ord instance Ord a => Ordable(Behavior a) where type Res (Behavior a) = Behavior Bool (>) = lift2 (Prelude.>) In this case, the result type is a behavior. Demo time!

  11. Phantom Types What’s a phantom type? A type variable that doesn’t correspond to an actual value: data Phantom a = Phantom You can use phantom types to keep track of information about data. data List a b = List [a] x :: List Int Size2 map :: (a -> b) -> List a s -> List b s

  12. Existential Types Type variables in Haskell normally are used with an implicit quantifier: for all. That is, data Tuple a b = Tuple a b works for all types a and b. When you add class constraints, you limit the type sets but this set is determined from “outside” the type.

  13. Using Existentials A data type that captures a single showable value: data Showable = forall a. Show a => Showable a How is this different from data Show a => Showable a = Showable a

  14. Existentials When you pattern match on a constructor that uses existentials, you get to use methods in the context: f :: Showable -> String f (Showable a) = show a

  15. GADTs and DSLs Why are GADTs good for DSLs? We can use the phantom type to keep track of information about data. Example!

  16. Quick Check http://wiki.western.edu/mcis/index.php/429/Week_6

More Related