1 / 9

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. Old Homework. http:// wiki.western.edu/mcis/index.php/429/Week_1 Questions?. Type Classes.

quinn-rosa
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. Old Homework • http://wiki.western.edu/mcis/index.php/429/Week_1 • Questions?

  3. Type Classes • A type class specifies a set of abstract operations that can be associated with a particular type class Similar a where isSimilar:: a -> a -> Bool notSimilar :: a -> a -> BoolnotSimilar x y = not $ isSimilarx y

  4. Instances An instance associates a type with a class: instance Similar Int where isSimilarx y = abs (x-y) < 2 How is this similar to Java? Different?

  5. Qualifiers When you use a function in a class, this brings the class name into the type signature: find :: (Similar a) => a -> [a] -> Bool find v = not . null . filter (\x -> isSimilar v x)

  6. Constraints in instances instance (Similar a, Similar b) => Similar (a, b) where isSimilar (x1, y1) (x2, y2) = isSimilar x1 x2 || isSimilar y1 y2

  7. Superclasses class Similar a => SuperSim a where reallySimilar :: a -> a -> Bool instance SuperSimInt where reallySimilar x y = isSimilarx y && x < y

  8. Built-in Classes • Off to haskell.org

  9. Derived Instances • Automatic code generation! data Foo = Foo IntInt deriving Show

More Related