Dr. Philip Cannata 1 Programming Languages Haskell.

Slides:



Advertisements
Similar presentations
Dr. Philip Cannata 1 Programming Languages Haskell Part 2.
Advertisements

2 Restricting and Sorting Data Important Legal Notice:  Materials on this lecture are from a book titled “Oracle Education” by Kochhar, Gravina, and Nathan.
12-1 Copyright  Oracle Corporation, All rights reserved. What Is a View? EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
Restricting and sorting data 16 May May May Created By Pantharee Sawasdimongkol.
Bogdan Shishedjiev SQL1 SQL Reminder of SQL. Bogdan Shishedjiev SQL 2 Subsets of language Data definition language (DDL) –Domain definition –Schema definition.
1Eyad Alshareef Enhanced Guide to Oracle 10g Chapter 3: Using SQL Queries to Insert, Update, Delete, and View Data.
Copyright  Oracle Corporation, All rights reserved. 2 Restricting and Sorting Data.
Copyright  Oracle Corporation, All rights reserved. 6 Writing Correlated Subqueries.
Writing Basic SQL statement 2 July July July Create By Pantharee Sawasdimongkol.
Session 3: SQL (B): Parts 3 & 4 Original materials supplied by the Oracle Academic Initiative (OAI). Edited for classroom use by Professor Laku Chidambaram.
Chapter 1 Writing Basic SQL Statements Important Legal Notice:  Materials on this lecture are from a book titled “Oracle Education” by Kochhar, Gravina,
Logical Operators Operator AND OR NOT Meaning Returns TRUE if both component conditions are TRUE Returns TRUE if either component condition is TRUE Returns.
Copyright  Oracle Corporation, All rights reserved. Introduction.
Dr. Philip Cannata 1 Doug Tolbert Unisys Doug Tolbert has been involved with OMG since the early 1990s. He is.
o At the end of this lesson, you will be able to:  Describe the life-cycle development phases  Discuss the theoretical and physical aspects of a relational.
Copyright  Oracle Corporation, All rights reserved. I Introduction.
Copyright  Oracle Corporation, All rights reserved. 1 Writing Basic SQL Statements.
4-1 Copyright  Oracle Corporation, All rights reserved. Displaying Data from Multiple Tables.
Dr. Philip Cannata 1 Programming Languages Prolog Part 3 SQL & Prolog.
After completing this lesson, you should be able to do the following: List the capabilities of MySQL SELECT statements Execute a basic SELECT statement.
1 Theory, Practice & Methodology of Relational Database Design and Programming Copyright © Ellis Cohen Introduction to Relational Databases &
1 Theory, Practice & Methodology of Relational Database Design and Programming Copyright © Ellis Cohen Cursors These slides are licensed under.
2 Writing Basic SELECT Statements. 1-2 Copyright  Oracle Corporation, All rights reserved. Capabilities of SQL SELECT Statements Selection Projection.
Copyright  Oracle Corporation, All rights reserved. Writing Basic SQL Statements.
An Introduction To SQL - Part 1 (Special thanks to Geoff Leese)
Copyright س Oracle Corporation, All rights reserved. I Introduction.
Copyright  Oracle Corporation, All rights reserved. 2 Restricting and Sorting Data.
RELATSIOONILISED ANDMEBAASID(alg) SQLi VÕIMALUSED.
Dr. Philip Cannata 1 Programming Languages. Dr. Philip Cannata 2 10 Java (Object Oriented) ASP RDF (Horn Clause Deduction, Semantic Web) Relation Jython.
Propositional Logic Dr. Rogelio Dávila Pérez Profesor-Investigador División de Posgrado Universidad Autónoma Guadalajara
SQL- DQL (Oracle Version). 2 SELECT Statement Syntax SELECT [DISTINCT] column_list FROM table_list [WHERE conditional expression] [GROUP BY column_list]
1 Theory, Practice & Methodology of Relational Database Design and Programming Copyright © Ellis Cohen Basic SQL These slides are licensed under.
Session 2: SQL (A): Parts 1 and 2 Original materials supplied by the Oracle Academic Initiative (OAI). Edited for classroom use by Professor Laku Chidambaram.
8 Producing Readable Output with SQL*Plus. 8-2 Objectives At the end of this lesson, you should be able to: Produce queries that require an input variable.
Dr. Philip Cannata 1 mgr Semantic Data Management.
1 Writing Basic SQL Statements. 1-2 Objectives At the end of this lesson, you should be able to: List the capabilities of SQL SELECT statements Execute.
I-1 Copyright س Oracle Corporation, All rights reserved. Data Retrieval.
SQL: Part 2 Original materials supplied by the Oracle Academic Initiative (OAI). Edited for classroom use by Professor Laku Chidambaram. Not for commercial.
CS 1813 Discrete Mathematics, Univ Oklahoma Copyright © 2000 by Rex Page 1 Lecture 2 CS 1813 – Discrete Mathematics Proofs Propositions and Calculuses.
Copyright  Oracle Corporation, All rights reserved. 12 Creating Views.
Copyright  Oracle Corporation, All rights reserved. 8 Producing Readable Output with SQL*Plus.
Dr. Philip Cannata 1 Programming Languages Chapter 19 - Continuations.
CS345 Project Presentation Language: H-- Mikhail Iakhiaev.
Copyright س Oracle Corporation, All rights reserved. I Introduction.
1 Theory, Practice & Methodology of Relational Database Design and Programming Copyright © Ellis Cohen Relational State Assertions These slides.
1 Theory, Practice & Methodology of Relational Database Design and Programming Copyright © Ellis Cohen Collection Operators These slides are.
Oracle CONNECT BY function JAVA WEB Programming. Emp 테이블의 내용 ( 상 / 하급자 계층구조 ) SQL> select * from emp; EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
2-1 Limiting Rows Using a Selection “…retrieve all employees in department 10” EMP EMPNO ENAME JOB... DEPTNO 7839KINGPRESIDENT BLAKEMANAGER CLARKMANAGER.
1 Theory, Practice & Methodology of Relational Database Design and Programming Copyright © Ellis Cohen Collection Operators These slides are.
Copyright س Oracle Corporation, All rights reserved. 12 Creating Views.
1-1 Copyright  Oracle Corporation, All rights reserved. Logging In to SQL*Plus From Windows environment:From Windows environment: From command line:From.
Copyright  All material contained herein is owned by Daniel Stober, the author of this presentation. This presentation and the queries, examples, and.
Copyright  Oracle Corporation, All rights reserved. 2 Restricting and Sorting Data.
Writing Basic SQL Statements. Objectives After completing this lesson, you should be able to do the following: –List the capabilities of SQL SELECT statements.
Defining a Column Alias
Copyright  Oracle Corporation, All rights reserved. Introduction.
Copyright س Oracle Corporation, All rights reserved. 1 Writing Basic SQL Statements.
Communicating with a RDBMS Using SQL Database SQL> SELECT loc 2 FROM dept; SQL> SELECT loc 2 FROM dept; SQL statement is entered Statement is sent to database.
Relational Normalization Theory
Programming Languages
Enhanced Guide to Oracle 10g
Programming Languages
Programming Languages
What Is a View? EMPNO ENAME JOB EMP Table EMPVU10 View
Programming Languages
Lecture 16 : The Relational Data Model
Writing Basic SQL Statements
Restricting and Sorting Data
Lecture 16 : The Relational Data Model
Presentation transcript:

Dr. Philip Cannata 1 Programming Languages Haskell

Dr. Philip Cannata 2 A programming language is a language with a well- defined syntax (lexicon and grammar), type system, and semantics that can be used to implement a set of algorithms. Haskell

Dr. Philip Cannata 3 Haskell: /lusr/bin/hugs, should be in your default $PATH or for windows, download and install winhugs at $ hugs __ __ __ __ ____ ___ _________________________________________ || || || || || || ||__ Hugs 98: Based on the Haskell 98 standard ||___|| ||__|| ||__|| __|| Copyright (c) ||---|| ___|| World Wide Web: || || Bugs: || || Version: _________________________________________ Haskell 98 mode: Restart with command line option -98 to enable extensions Type :? for help Hugs> :load 09H1 Main> To load the file “09H1.hs” from the directory in which you started hugs

Dr. Philip Cannata 4 Hugs> 2 * 4 ^2 32 Hugs> 8^2 64 Hugs> (2 * 4) ^ 2 64 Hugs> ^ 2 18 Hugs> 2 ^ Hugs> True && False False Hugs> True || False True Hugs> 3 < 5 True Hugs> 'c' < 'p' True Hugs> 'c' > 'p' False Hugs> "tree" < "rock" False Hugs> "tree" > "rock" True Haskell Expression Number Expressions Boolean Expressions Character Expressions String Expressions

Dr. Philip Cannata 5 Hugs> ("dog", "cat", 5) ("dog","cat",5) Hugs> ["dog", "cat", 5] ERROR - Cannot infer instance *** Instance : Num [Char] *** Expression : ["dog","cat",5] Hugs> ["dog", "cat", "5"] ["dog","cat","5"] Hugs> 1 : [] [1] Hugs> 1 : [2,3,4] [1,2,3,4] [expression | generator] Hugs> [2 * x ^ 2 | x <- [1, 2, 3,4]] [2,8,18,32] Hugs> [x * y | (x, y) <- [(1, 2), (3, 4), (5, 6)]] [2,12,30] Haskell Basic Data Structures Tuples Lists List Construction List Comprehension

Dr. Philip Cannata 6 Hugs> [(x, y) | x <- [1, 3.. 6], y <- ['a', 'b', 'c', 'd']] [(1,'a'),(1,'b'),(1,'c'),(1,'d'),(3,'a'),(3,'b'),(3,'c'),(3,'d'),(5,'a'),(5,'b'),(5,'c'),(5,'d')] Hugs> [(x, y) | x <- [1..4], y <- [1..4]] [(1,1),(1,2),(1,3),(1,4),(2,1),(2,2),(2,3),(2,4),(3,1),(3,2),(3,3),(3,4),(4,1),(4,2), (4,3),(4,4)] Hugs> [(x, y) | x <- [0..4], y <- [0..4], x < y] [(0,1),(0,2),(0,3),(0,4),(1,2),(1,3),(1,4),(2,3),(2,4),(3,4)] Hugs> [(x, y) | x y] [(1,0),(2,0),(2,1),(3,0),(3,1),(3,2),(4,0),(4,1),(4,2),(4,3)] Hugs> [x | x <- [1..100], y <- [1..100], 72 == x * y] [1,2,3,4,6,8,9,12,18,24,36,72] Haskell Basic Data Structures continued List Comprehension Cross product “ ” Relation Factors of 72

Dr. Philip Cannata 7 Main> [empno | (empno, _, _, _, _, _, _) <- emp] [7839,7698,7782,7566,7788,7902,7369,7499,7521,7654,7844,7876,7900, 7934] Main> [empno | (empno, _, _, _, _, sal, _) 4000] [7839] Main> [empno | (empno, _, _, _, _, sal, _) 2000] [7839,7698,7782,7566,7788,7902] Haskell Basic Data Structures - continued List Comprehension Database Query

Dr. Philip Cannata 8 Hugs> :type product product :: Num a => [a] -> a Hugs> product [ 2, 3, 4 ] 24 Hugs> product [ x | x <- [1..10]] Hugs> :type (+) (+) :: Num a => a -> a -> a Hugs> Hugs> (+) Hugs> (\ x -> x ^ 2 + 4) 5 29 Haskell Functions product Function (+) Operator – an Operator is a 2-ary Function lambdas

Dr. Philip Cannata 9 Hugs> :type not not :: Bool -> Bool Hugs> not True False Hugs> :type map map :: (a -> b) -> [a] -> [b] Hugs> map sqrt [ 1, 4, 9, 10 ] [1.0,2.0,3.0, ] Hugs> map (\ x -> x + 2) [ 1, 2, 3, 4] [3,4,5,6] Hugs> :type head head :: [a] -> a Hugs> head [ 5, 4, 3, 2, 1] 5 Haskell Pattern Matching not :: Bool  Bool not False = True not True = False map :: (a -> b) -> [a] -> [b] map _ [] = [] map f (x:xs) = f x : map f xs head :: [a] -> a head = ( \(x:xs) -> x)

Dr. Philip Cannata 10 Hugs> if True then 6 else 8 6 Hugs> if False then 6 else 8 8 Hugs> 2 + let x = sqrt 9 in (x + 1) * (x - 1) 10.0 Haskell Conditional Expressions Let Expressions (i.e., local variables) not :: Bool  Bool not False = True not True = False Let assignment assignment. in (expression)

Dr. Philip Cannata 11 v = 1/0 testLazy x = testLazy1 x = 2 / x Hugs> v 1.#INF Hugs > testLazy Hugs > testLazy v 12 Hugs > testLazy e-2 Hugs > testLazy1 v 0.0 Hugs > (\x -> let y = x in (2 / y)) (1/0) 0.0 Hugs > (\x -> let y = x in (2 / y)) (0) 1.#INF Lazy Evaluation

Dr. Philip Cannata 12 Propositions: Statements that can be either True or False Logical Operators: Negation: not not :: Bool-> Bool not True = False not False = True Conjunction: && (&&) :: Bool-> Bool-> Bool False && x = False True && x = x Disjunction: || (||) :: Bool-> Bool-> Bool True || x = True False || x = x Propositional Logic Logical Operators: Implication (if – then): ==> Antecedent ==> Consequent (==>) :: Bool -> Bool -> Bool x ==> y = (not x) || y Equivalence (if, and only if): ( ) :: Bool -> Bool -> Bool x y = x == y Not Equivalent ( ) :: Bool -> Bool -> Bool x y = x /= y

Dr. Philip Cannata 13 Truth tables: P && Q P || Q not P P ==> Q P Q P Q P && Q False False False False True False True False False True True True P Q P || Q False False False False True True True False True True True True P  P False True True False P Q P  Q False False True False True True True False False True True True P Q P Q False False True False True False True False False True True True P Q P Q False False False False True True True False True True True False

Dr. Philip Cannata 14 Proposition (WFF): ((P  Q)  ((  P)  Q)) P Q False False True True False True False True (P  Q) (  P) True False ((  P)  Q) False True ((P  Q)  ((  P)  Q)) False True Some True: prop is Satisfiable* If they were all True: Valid / Tautology All False: Contradiction (not satisfiable*) * Satisfiability was the first known NP-complete problem If prop is True when all variables are True: P, Q ((P  Q)  ((  P)  Q)) A Truth double turnstile Reasoning with Truth Tables

Dr. Philip Cannata 15 truthTable :: (Bool -> Bool -> Bool) -> [Bool] truthTable wff = [ (wff p q) | p <- [True,False], q <- [True,False]] tt = (\ p q -> not (p ==> q)) Hugs> :load 10Logic.hs LOGIC> :type tt tt :: Bool -> Bool -> Bool LOGIC> truthTable tt [False,True,False,False] LOGIC> or (truthTable tt) True LOGIC> and (truthTable tt) False Truth Table Application

Dr. Philip Cannata 16 Satisfiable: Are there well formed propositional formulas that return True for some input? satisfiable1 :: (Bool -> Bool) -> Bool satisfiable1 wff = (wff True) || (wff False) satisfiable2 :: (Bool -> Bool -> Bool) -> Bool satisfiable2 wff = or [ (wff p q) | p <- [True,False], q <- [True,False]] satisfiable3 :: (Bool -> Bool -> Bool -> Bool) -> Bool satisfiable3 wff = or [ (wff p q r) | p <- [True,False], q <- [True,False], r <- [True,False]] ( \ p -> not p) ( \ p q -> (not p) || (not q) ) ( \ p q r -> (not p) || (not q) && (not r) ) Define these first infix 1 ==> (==>) :: Bool -> Bool -> Bool x ==> y = (not x) || y infix 1 ( ) :: Bool -> Bool -> Bool x y = x == y infixr 2 ( ) :: Bool -> Bool -> Bool x y = x /= y

Dr. Philip Cannata 17 Validity (Tautology): Are there well formed propositional formulas that return True no matter what their input values are? valid1 :: (Bool -> Bool) -> Bool valid1 wff = (wff True) && (wff False) valid2 :: (Bool -> Bool -> Bool) -> Bool valid2 wff = (wff True True) && (wff True False) && (wff False True) && (wff False False) ( \ p -> p || not p ) -- Excluded Middle ( \ p -> p ==> p ) ( \ p q -> p ==> (q ==> p) ) ( \ p q -> (p ==> q) ==> p )

Dr. Philip Cannata 18 Contradiction (Not Satisfiable): Are there well formed propositional formulas that return False no matter what their input values are? contradiction1 :: (Bool -> Bool) -> Bool contradiction1 wff = not (wff True) && not (wff False) contradiction2 :: (Bool -> Bool -> Bool) -> Bool contradiction2 wff = and [not (wff p q) | p <- [True,False], q <- [True,False]] contradiction3 :: (Bool -> Bool -> Bool -> Bool) -> Bool contradiction3 wff = and [ not (wff p q r) | p <- [True,False], q <- [True,False], r <- [True,False]] ( \ p -> p && not p) ( \ p q -> (p && not p) || (q && not q) ) ( \ p q r -> (p && not p) || (q && not q) && (r && not r) )

Dr. Philip Cannata 19 Truth: Are there well formed propositional formulas that return True when their input is True truth1 :: (Bool -> Bool) -> Bool truth1 wff = (wff True) truth2 :: (Bool -> Bool -> Bool) -> Bool truth2 wff = (wff True True) ( \ p -> not p) ( \ p q -> (p && q) || (not p ==> q)) ( \ p q -> not p ==> q) ( \ p q -> (not p && q) && (not p ==> q) )

Dr. Philip Cannata 20 Equivalence: logEquiv1 :: (Bool -> Bool) -> (Bool -> Bool) -> Bool logEquiv1 bf1 bf2 = (bf1 True bf2 True) && (bf1 False bf2 False) logEquiv2 :: (Bool -> Bool -> Bool) -> (Bool -> Bool -> Bool) -> Bool logEquiv2 bf1 bf2 = and [(bf1 r s) (bf2 r s) | r <- [True,False], s <- [True,False]] logEquiv3 :: (Bool -> Bool -> Bool -> Bool) -> (Bool -> Bool -> Bool -> Bool) -> Bool logEquiv3 bf1 bf2 = and [(bf1 r s t) (bf2 r s t) | r <- [True,False], s <- [True,False], t <- [True,False]] formula3 p q = p formula4 p q = (p q) q formula5 p q = p ((p q) q) *Haskell> logEquiv2 formula3 formula4 True *Haskell> logEquiv2 formula4 formula5 False

Dr. Philip Cannata 21 Equivalence continued: logEquiv1 id (\ p -> not (not p)) logEquiv1 id (\ p -> p && p) logEquiv1 id (\ p -> p || p) logEquiv2 (\ p q -> p ==> q) (\ p q -> not p || q) logEquiv2 (\ p q -> not (p ==> q)) (\ p q -> p && not q) logEquiv2 (\ p q -> not p ==> not q) (\ p q -> q ==> p) logEquiv2 (\ p q -> p ==> not q) (\ p q -> q ==> not p) logEquiv2 (\ p q -> not p ==> q) (\ p q -> not q ==> p) logEquiv2 (\ p q -> p q) (\ p q -> (p ==> q) && (q ==> p)) logEquiv2 (\ p q -> p q) (\ p q -> (p && q) || (not p && not q)) logEquiv2 (\ p q -> p && q) (\ p q -> q && p) logEquiv2 (\ p q -> p || q) (\ p q -> q || p) logEquiv2 (\ p q -> not (p && q)) (\ p q -> not p || not q) logEquiv2 (\ p q -> not (p || q)) (\ p q -> not p && not q) logEquiv3 (\ p q r -> p && (q && r)) (\ p q r -> (p && q) && r) logEquiv3 (\ p q r -> p || (q || r)) (\ p q r -> (p || q) || r) logEquiv3 (\ p q r -> p && (q || r)) (\ p q r -> (p && q) || (p && r)) test9b logEquiv3 (\ p q r -> p || (q && r)) (\ p q r -> (p || q) && (p || r)) -- Idempotence -- Implication -- Contrapositive -- Commutativity -- deMorgan -- Associativity -- Distributivity

Dr. Philip Cannata 22 Why Reasoning with Truth Tables is Infeasible Works fine when there are 2 variables {T,F}  {T,F} = set of potential values of variables 2  2 lines in truth table Three variables — starts to get tedious {T,F}  {T,F}  {T,F} = set of potential values 2  2  2 lines in truth table Twenty variables — definitely out of hand 2  2  …  2 lines (220) You want to look at a million lines? If you did, how would you avoid making errors? Hundreds of variables — not in a million years  A need for Predicate Logic. We’ll look at this with Prolog.

Dr. Philip Cannata 23 Haskell and SQL

Dr. Philip Cannata 24 Standard Oracle scott/tiger emp dept database

Dr. Philip Cannata 25 emp = [ (7839, "KING", "PRESIDENT", 0, "17-NOV-81", 5000, 10), (7698, "BLAKE", "MANAGER", 7839, "01-MAY-81", 2850, 30), (7782, "CLARK", "MANAGER", 7839, "09-JUN-81", 2450, 10), (7566, "JONES", "MANAGER", 7839, "02-APR-81", 2975, 20), (7788, "SCOTT", "ANALYST", 7566, "09-DEC-82", 3000, 20), (7902, "FORD", "ANALYST", 7566, "03-DEC-81", 3000, 20), (7369, "SMITH", "CLERK", 7902, "17-DEC-80", 800, 20), (7499, "ALLEN", "SALESMAN", 7698, "20-FEB-81", 1600, 30), (7521, "WARD", "SALESMAN", 7698, "22-FEB-81", 1250, 30), (7654, "MARTIN", "SALESMAN", 7698, "28-SEP-81", 1250, 30), (7844, "TURNER", "SALESMAN", 7698, "08-SEP-81", 1500, 30), (7876, "ADAMS", "CLERK", 7788, "12-JAN-83", 1100, 20), (7900, "JAMES", "CLERK", 7698, "03-DEC-81", 950, 30), (7934, "MILLER", "CLERK", 7782, "23-JAN-82", 1300, 10) ] dept = [ (10, "ACCOUNTING", "NEW YORK"), (20, "RESEARCH", "DALLAS"), (30, "SALES", "CHICAGO"), (40, "OPERATIONS", "BOSTON") ] Standard Oracle scott/tiger emp dept database in Haskell

Dr. Philip Cannata 26 Main>Main> [(empno, ename, job, sal, deptno) | (empno, ename, job, _, _, sal, deptno) <- emp] [(7839,"KING","PRESIDENT",5000,10), (7698,"BLAKE","MANAGER",2850,30), (7782,"CLARK","MANAGER",2450,10), (7566,"JONES","MANAGER",2975,20), (7788,"SCOTT","ANALYST",3000,20), (7902,"FORD","ANALYST",3000,20), (7369,"SMITH","CLERK",800,20), (7499,"ALLEN","SALESMAN",1600,30), (7521,"WARD","SALESMAN",1250,30), (7654,"MARTIN","SALESMAN",1250,30), (7844,"TURNER","SALESMAN",1500,30), (7876,"ADAMS","CLERK",1100,20), (7900,"JAMES","CLERK",950,30), (7934,"MILLER","CLERK",1300,10)] Main>

Dr. Philip Cannata 27 Main> [(empno, ename, job, sal, deptno) | (empno, ename, job, _, _, sal, deptno) <- emp, deptno == 10] [(7839,"KING","PRESIDENT",5000,10), (7782,"CLARK","MANAGER",2450,10), (7934,"MILLER","CLERK",1300,10)] Main>

Dr. Philip Cannata 28 Main> [(empno, ename, job, sal, dname) | (empno, ename, job, _, _, sal, edeptno) <- emp, (deptno, dname, loc) <- dept, edeptno == deptno ] [(7839,"KING","PRESIDENT",5000,"ACCOUNTING"), (7698,"BLAKE","MANAGER",2850,"SALES"), (7782,"CLARK","MANAGER",2450,"ACCOUNTING"), (7566,"JONES","MANAGER",2975,"RESEARCH"), (7788,"SCOTT","ANALYST",3000,"RESEARCH"), (7902,"FORD","ANALYST",3000,"RESEARCH"), (7369,"SMITH","CLERK",800,"RESEARCH"), (7499,"ALLEN","SALESMAN",1600,"SALES"), (7521,"WARD","SALESMAN",1250,"SALES"), (7654,"MARTIN","SALESMAN",1250,"SALES"), (7844,"TURNER","SALESMAN",1500,"SALES"), (7876,"ADAMS","CLERK",1100,"RESEARCH"), (7900,"JAMES","CLERK",950,"SALES"), (7934,"MILLER","CLERK",1300,"ACCOUNTING")] Main>

Dr. Philip Cannata 29 Main> length [sal | (_, _, _, _, _, sal, _) <- emp] 14 Main> Main> (\y -> fromIntegral(sum y) / fromIntegral(length y)) ([sal | (_, _, _, _, _, sal, _) <- emp]) Main>

Dr. Philip Cannata 30 Main> map sqrt (map fromIntegral [sal | (_, _, _, _, _, sal, _) <- emp]) [ , , , , , , 40.0, , , , , ] Main>

Dr. Philip Cannata 31 Main> (map sqrt. map fromIntegral) [sal | (_, _, _, _, _, sal, _) <- emp] [ , , , , , , 40.0, , , , , ] Main>

Dr. Philip Cannata 32 Main> zip ([name | (_, name, _, _, _, _, _) <- emp]) (map sqrt (map fromIntegral [sal | (_, _, _, _, _, sal, _) <- emp])) [("KING", ), ("BLAKE", ), ("CLARK", ), ("JONES", ), ("SCOTT", ), ("FORD", ), ("SMITH", ), ("ALLEN",40.0), ("WARD", ), ("MARTIN", ), ("TURNER", ), ("ADAMS", ), ("JAMES", ), ("MILLER", )] Main>

Dr. Philip Cannata 33 Main> [(name, sal, dept) | (_, name, _, _, _, sal, dept) <- emp, dept `elem` [20, 30]] [("BLAKE",2850,30), ("JONES",2975,20), ("SCOTT",3000,20), ("FORD",3000,20), ("SMITH",800,20), ("ALLEN",1600,30), ("WARD",1250,30), ("MARTIN",1250,30), ("TURNER",1500,30), ("ADAMS",1100,20), ("JAMES",950,30)] Main>

Dr. Philip Cannata 34 Main> [(name, sal, dept) | (_, name, _, _, _, sal, dept) <- emp, dept `notElem` [20, 30]] [("KING",5000,10), ("CLARK",2450,10), ("MILLER",1300,10)] Main>

Dr. Philip Cannata 35 Main> [(name, sal, dept) | (_, name, _, _, _, sal, dept) <- emp, dept `notElem` [20, 30]] ++ [(name, sal, dept) | (_, name, _, _, _, sal, dept) <- emp, dept `elem` [20, 30]] [("KING",5000,10), ("CLARK",2450,10), ("MILLER",1300,10), ("BLAKE",2850,30), ("JONES",2975,20), ("SCOTT",3000,20), ("FORD",3000,20), ("SMITH",800,20), ("ALLEN",1600,30), ("WARD",1250,30), ("MARTIN",1250,30), ("TURNER",1500,30), ("ADAMS",1100,20), ("JAMES",950,30)] Main>

Dr. Philip Cannata 36