CSE 341 : Programming Languages

CSE 341 : Programming Languages
Slide Note
Embed
Share

This course, CSE 341, focuses on the programming language Haskel. Dive into Haskell programming concepts, applications, and practices in this autumn 2015 offering. Explore the unique features and capabilities of Haskell in an academic environment. Gain insights into functional programming paradigms and language design through hands-on exercises and projects. Elevate your programming skills by engaging with Haskell's innovative techniques and tools. This course will provide a solid foundation for understanding functional programming principles and their real-world applications.

  • Programming Languages
  • Haskell
  • Autumn 2015
  • Functional Programming
  • Academic Environment

Uploaded on Feb 17, 2025 | 0 Views


Download Presentation

Please find below an Image/Link to download the presentation.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author.If you encounter any issues during the download, it is possible that the publisher has removed the file from their server.

You are allowed to download the files provided on this website for personal or commercial use, subject to the condition that they are used lawfully. All files are the property of their respective owners.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author.

E N D

Presentation Transcript


  1. CSE 341 : Programming Languages Section 4 Haskel #2 Autumn 2015

  2. Reminders Homework 3 due last night up to two late days questions after section / in office hours Office hours remaining: Justin Adsuara (justbads at cs) OH: Thurs 3:30-4:20, CSE 002 Alan Borning (borning at cs) OH: Fri 4:30-5:20, or by appointment, or whenever the door is open. CSE 478 2

  3. Reminders Anonymous functions: plus x y = x + y can be defined in an expression as: (\x -> \y -> x + y) Currying: plus 7 is like the partial evaluation: plus y = 7 + y (\y -> 7 + y) or: User Types (simple): data NAME PARAM(s) = VALUE1 | VALUE2 | constructs (i.e. deriving (Show, Read)) 3

  4. Reminders Higher order functions: one or more arguments are functions [map, filter, ] Function composition: [ . ] f . g (of x, x can be omitted) compose f g x = f (g x) though] is like: [Need the x here, Pointfree programming: [omitting the argument] incr = plus 1 incr a = plus 1 a Is sugar for: 4

  5. Exercises [Haskell mini #2] 5

  6. Exercises [Haskell mini #2] data List a = Empty | Cell a (List a) deriving (Show,Read) 6

  7. Exercises [Haskell mini #2] data List a = Empty | Cell a (List a) deriving (Show,Read) append :: List a -> List a -> List a append Empty ys = ys append (Cell x xs) ys = Cell x (append xs ys) 7

  8. Exercises [Haskell mini #2] data List a = Empty | Cell a (List a) deriving (Show,Read) append :: List a -> List a -> List a append Empty ys = ys append (Cell x xs) ys = Cell x (append xs ys) mymap :: (t -> a) -> List t -> List a mymap f Empty = Empty mymap f (Cell x xs) = Cell (f x) (mymap f xs) Questions? 8

  9. Exercises [Section] data List a = Empty | Cell a (List a) deriving (Show,Read) append :: List a -> List a -> List a append Empty ys = ys append (Cell x xs) ys = Cell x (append xs ys) mymap :: (t -> a) -> List t -> List a mymap f Empty = Empty mymap f (Cell x xs) = Cell (f x) (mymap f xs) numlist = Cell 1 (Cell 2 ( Cell 3)) What is the result of; mymap (\x -> 1 + x) numlist 9

  10. Exercises [Section] data List a = Empty | Cell a (List a) deriving (Show,Read) append :: List a -> List a -> List a append Empty ys = ys append (Cell x xs) ys = Cell x (append xs ys) mymap :: (t -> a) -> List t -> List a mymap f Empty = Empty mymap f (Cell x xs) = Cell (f x) (mymap f xs) numlist = Cell 1 (Cell 2 ( Cell 3)) What is the result of; mymap (\x -> 1 + x) numlist ERROR! Why? 10

  11. Exercises [Section] data List a = Empty | Cell a (List a) deriving (Show,Read) append :: List a -> List a -> List a append Empty ys = ys append (Cell x xs) ys = Cell x (append xs ys) mymap :: (t -> a) -> List t -> List a mymap f Empty = Empty mymap f (Cell x xs) = Cell (f x) (mymap f xs) numlist = Cell 1 (Cell 2 ( Cell 3)) What is the result of; mymap (\x -> 1 + x) numlist ERROR! Why? Cell 3 is missing its second argument of type List 11

  12. Exercises [Section] data List a = Empty | Cell a (List a) deriving (Show,Read) append :: List a -> List a -> List a append Empty ys = ys append (Cell x xs) ys = Cell x (append xs ys) mymap :: (t -> a) -> List t -> List a mymap f Empty = Empty mymap f (Cell x xs) = Cell (f x) (mymap f xs) numlist = Cell 1 (Cell 2 (Cell 3 ????)) What is the result of: mymap (\x -> 1 + x) numlist 12

  13. Exercises [Section] data List a = Empty | Cell a (List a) deriving (Show,Read) append :: List a -> List a -> List a append Empty ys = ys append (Cell x xs) ys = Cell x (append xs ys) mymap :: (t -> a) -> List t -> List a mymap f Empty = Empty mymap f (Cell x xs) = Cell (f x) (mymap f xs) numlist = Cell 1 (Cell 2 ( Cell 3 Empty)) What is the result of: mymap (\x -> 1 + x) numlist Cell 2 (Cell 3 ( Cell 4 Empty)) Questions? 13

  14. Homework[Interpreter] questions? 14

More Related Content