This preview shows pages 1–6. Sign up to view the full content.
This preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentThis preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentThis preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
Unformatted text preview: CS2603 Applied Logic for Hardware and Software Rex Page University of Oklahoma 1 Lecture 15 CS 2603 Applied Logic for Hardware and Software Patterns of Computation CS2603 Applied Logic for Hardware and Software Rex Page University of Oklahoma 2 Type Specifications Every Haskell Entity Has a Type x, y, z :: Integer  this is a type spec, not an axiom x, y, and z have type Integer Examples of equations defining x, y, and z x = 1 this is an axiom: x means 1 y = 3 + 7 another axiom: y means 10 z = sum[49, 12, 22, 19]  the variable z means 64 xs, ys :: [Integer] xs and ys are sequences with elements of type Integer Examples of axioms defining xs and ys xs = [29, 2, x, 3*y, 0, x+z] Equivalent axiom: xs = [29, 2, 1, 30, 0, 65] ys = [1 .. 4] ++ xs Equivalent axiom: ys = [1, 2, 3,4] ++ [ 29, 2, 1, 30, 0, 65] Another equivalent axiom: ys = [1, 2, 3,4, 29, 2, 1, 30, 0, 65] CS2603 Applied Logic for Hardware and Software Rex Page University of Oklahoma 3 More Type Specifications Functions Have Types, Too or :: [Bool] > Bool  a type spec for a function or is a function 9 Any type spec with an arrow in it is a function type 9 One argument (number of arguments equals number of arrows) 9 Argument is a sequence with elements of type Bool 9 Delivers a value of type Bool (\/), (/\) :: Bool > Bool > Bool  type spec for two functions (\/) and (/\) are functions with two arguments (2 arrows, 2 args) Both arguments have type Bool Value delivered has type Bool Formulas can use these functions with prefix or infix syntax 9 Formula using prefix syntax: (\/) False True 9 Formula using infix syntax : False \/ True 9 Parentheses around an infix operator converts to prefix syntax 9 Backquotes around a prefix function converts to infix syntax (Assume A) `OrI` (A \/ B) CS2603 Applied Logic for Hardware and Software Rex Page University of Oklahoma 4 Generic Type Specifications Functions Can Span Many Types (++) :: [e] > [e] > [e]  generic type spec (++) is a function with two arguments, both of which are sequences 9 [e] specifies a sequence with elements of type e 9 e is a type variable 9 This type specification places no constraints on e it can be any type 9 Both argument sequences must have the same type of elements Formulas using ++ [True, False, True] ++ [False] e is the type Bool in this case [Gdel] ++ [Backus, Dijkstra]  e is the type String in this case [4, 2, 12, 9] ++ [6, 8] e is a numeric type in this case CS2603 Applied Logic for Hardware and Software Rex Page University of Oklahoma 5 Generic Types Can Be Constrained sum :: Num x => [x] > x this is a type spec Doubleshafted arrow delimits type constraint Num is the class of numeric types 9 A class is a set of types 9 Num x constrains x to be in the class Num 9 Num consists of all types for which +, , and 0 are defined 9 Num = {Integer, Rational, Float, Double, Complex, }...
View
Full
Document
This note was uploaded on 04/08/2008 for the course CS 2603 taught by Professor Rexpage during the Spring '08 term at The University of Oklahoma.
 Spring '08
 RexPage

Click to edit the document details