Introduction to Programming and 4Algorithms Abstract Types. Uwe R. Zimmer - The Australian National University
|
|
- Spencer George
- 5 years ago
- Views:
Transcription
1 Introduction to Programming and 4Algorithms 2015 Uwe R. Zimmer - The Australian National University
2 [ Thompson2011 ] Thompson, Simon Haskell - The craft of functional programming Addison Wesley, third edition 2011 References 2015 Uwe R. Zimmer, The Australian National University page 335 of 794 (chapter 4: up to page 369)
3 Definition An abstract type is defined by 1. A type name the type structure can be partly revealed or stay completely hidden and can be as simple as a character or as complicated as a database. 2. Functions / Operations which work on this type and have to follow defined rules, like an e.g. arithmetic laws or a specific algebra Uwe R. Zimmer, The Australian National University page 336 of 794 (chapter 4: up to page 369)
4 Definition An abstract type is defined by 1. A type name the type structure can be partly revealed or stay completely hidden and can be as simple as a character or as complicated as a database. 2. Functions / Operations which work on this type and have to follow defined rules, like an e.g. arithmetic laws or a specific algebra. What s abstract? We don t necessarily know how values are stored in memory or how the operations are implemented. we can for instance use a floating point number without knowing which bit goes where, or how the sine function is implemented 2015 Uwe R. Zimmer, The Australian National University page 337 of 794 (chapter 4: up to page 369)
5 Definition An abstract type is defined by 1. A type name the type structure can be partly revealed or stay completely hidden and can be as simple as a character or as complicated as a database. 2. Functions / Operations which work on this type and have to follow defined rules, like an e.g. arithmetic laws or a specific algebra. What s abstract? We don t necessarily know how values are stored in memory or how the operations are implemented. All good programming interfaces are designed on a need to know basis. we can for instance use a floating point number without knowing which h bit goes where, or how the sine function is implemented 2015 Uwe R. Zimmer, The Australian National University page 338 of 794 (chapter 4: up to page 369)
6 Enumerations: Basic types Basic, scalar types overview Boolean (Bool), Characters (Char) Numbers: Cardinal (-), Integer (Integer), Integer range (Ix), Rational (Rational), Real (Float, Double), Complex (Complex) Machine related types: Bits (Bits), N Words: Integer range 0f 2-1 (Word, WordN), N- Two s complements: Integer range 2 1 N- - f (Int, IntN) with N! 2015 Uwe R. Zimmer, The Australian National University page 339 of 794 (chapter 4: up to page 369)
7 Enumerations Boolean (Bool) Constructors: data Bool = False True Base functions: and (&&), or ( ), not (not) (&&), ( ) :: Bool -> Bool -> Bool not :: Bool -> Bool 2015 Uwe R. Zimmer, The Australian National University page 340 of 794 (chapter 4: up to page 369)
8 Enumerations Boolean (Bool) Constructors: data Bool = False True Base functions: and (&&), or ( ), not (not) (&&), ( ) :: Bool -> Bool -> Bool not :: Bool -> Bool Some related functions: (==), (/=) :: Eq a => a -> a -> Bool (<), (<=), (>=), (>) :: Ord a => a -> a -> Bool isnan, isinfinite, isdenormalized, isnegativezero, isieee :: RealFloat a => a -> Bool 2015 Uwe R. Zimmer, The Australian National University page 341 of 794 (chapter 4: up to page 369)
9 Enumerations Boolean (Bool) Constructors: data Bool = False True Base functions: and (&&), or ( ), not (not) (&&), ( ) :: Bool -> Bool -> Bool not :: Bool -> Bool Some related functions: (==), (/=) :: Eq a => a -> a -> Bool (<), (<=), (>=), (>) :: Ord a => a -> a -> Bool isnan, isinfinite, isdenormalized, isnegativezero, isieee :: RealFloat a => a -> Bool Example functions: threshold_reached :: Integer -> Bool threshold_reached number = number > 100 and_3 :: Bool -> Bool -> Bool -> Bool and_3 x y z = x && y && z 2015 Uwe R. Zimmer, The Australian National University page 342 of 794 (chapter 4: up to page 369)
10 Enumerations Boolean (Bool) Example function Exclusive or : ex_or1 :: Bool -> Bool -> Bool ex_or1 x y = case (x, y) of (False, False) -> False (False, True ) -> True (True, False) -> True (True, True ) -> False 2015 Uwe R. Zimmer, The Australian National University page 343 of 794 (chapter 4: up to page 369)
11 Enumerations Boolean (Bool) Example function Exclusive or : ex_or1 :: Bool -> Bool -> Bool ex_or1 x y = case (x, y) of (False, False) -> False (False, True ) -> True (True, False) -> True (True, True ) -> False ex_or2 :: Bool -> Bool -> Bool ex_or2 x y = case x of False -> y True -> not y 2015 Uwe R. Zimmer, The Australian National University page 344 of 794 (chapter 4: up to page 369)
12 Enumerations Boolean (Bool) Example function Exclusive or : ex_or1 :: Bool -> Bool -> Bool ex_or1 x y = case (x, y) of (False, False) -> False (False, True ) -> True (True, False) -> True (True, True ) -> False ex_or2 :: Bool -> Bool -> Bool ex_or2 x y = case x of False -> y True -> not y ex_or3 :: Bool -> Bool -> Bool ex_or3 x y = (x && not y) (not x && y) 2015 Uwe R. Zimmer, The Australian National University page 345 of 794 (chapter 4: up to page 369)
13 Enumerations Boolean (Bool) Example function Exclusive or : ex_or1 :: Bool -> Bool -> Bool ex_or1 x y = case (x, y) of (False, False) -> False (False, True ) -> True (True, False) -> True (True, True ) -> False ex_or2 :: Bool -> Bool -> Bool ex_or2 x y = case x of False -> y True -> not y ex_or4 :: Bool -> Bool -> Bool ex_or4 x y = x /= y ex_or3 :: Bool -> Bool -> Bool ex_or3 x y = (x && not y) (not x && y) 2015 Uwe R. Zimmer, The Australian National University page 346 of 794 (chapter 4: up to page 369)
14 Enumerations Boolean (Bool) Testing example implementations: import Test.QuickCheck test_ex_ors :: Bool -> Bool -> Bool test_ex_ors x y = (ex_or1 x y) == (ex_or2 x y) && (ex_or2 x y) == (ex_or3 x y) && (ex_or3 x y) == (ex_or4 x y) > quickcheck test_ex_ors +++ OK, passed 100 tests Uwe R. Zimmer, The Australian National University page 347 of 794 (chapter 4: up to page 369)
15 Enumerations Boolean (Bool) Boolean algebra: (a && b) && c == a && (b && c) (a b) c == a (b c) (associative) a && b == b && a a b == b a (commutative) a && (a b) == a a (a && b) == a (absorption) a && (b c) == (a && b) (a && c) a (b && c) == (a b) && (a c) (distribution) a && not a == False a not a == True (complement) Those basic laws (which are one way to axiomatize the boolean algebra) may help to simplify logic expressions. Compilers might use them as well to provide warnings like This guard expression will always be False, hence the following code is unreachable Uwe R. Zimmer, The Australian National University page 348 of 794 (chapter 4: up to page 369)
16 Enumerations Boolean (Bool) Constructors: data Bool = False True Base functions: and (&&), or ( ), not (not) (&&), ( ) :: Bool -> Bool -> Bool not :: Bool -> Bool Algebra: (a && b) && c == a && (b && c) (a b) c == a (b c) (associative) a && b == b && a a b == b a (commutative) a && (a b) == a a (a && b) == a (absorption) a && (b c) == (a && b) (a && c) a (b && c) == (a b) && (a c) (distribution) a && not a == False a not a == True (complement) 2015 Uwe R. Zimmer, The Australian National University page 349 of 794 (chapter 4: up to page 369)
17 Enumerations Boolean (Bool) Constructors: data Bool = False True Base functions: and (&&), or ( ), not (not) (&&), ( ) :: Bool -> Bool -> Bool not :: Bool -> Bool An abstract type is defined by its name plus operations (functions) which have to follow certain rules (algebra). Algebra: (a && b) && c == a && (b && c) (a b) c == a (b c) (associative) a && b == b && a a b == b a (commutative) a && (a b) == a a (a && b) == a (absorption) a && (b c) == (a && b) (a && c) a (b && c) == (a b) && (a c) (distribution) a && not a == False a not a == True (complement) 2015 Uwe R. Zimmer, The Australian National University page 350 of 794 (chapter 4: up to page 369)
18 Enumerations Character (Char) Definition: data Char = Enumeration of Unicode Characters (ISO/IEC 10646) in UTF-32 first 128 characters are identical to ASCII, first 256 characters are identical to ISO (Latin-1). Base functions: iscontrol, isspace, islower, isupper, isalpha, isalphanum, isprint, isdigit, isoctdigit, ishexdigit, isletter, ismark, isnumber, ispunctuation, issymbol, is- Separator, isascii, islatin1, isasciiupper, isasciilower :: Char -> Bool generalcategory :: Char -> GeneralCategory (Emumeration of Unicode categories) toupper, tolower, totitle :: Char -> Char digittoint :: Char -> Int inttodigit :: Int -> Char (works for hexadecimal characters / values too) ord :: Char -> Int chr :: Int -> Char 2015 Uwe R. Zimmer, The Australian National University page 351 of 794 (chapter 4: up to page 369)
19 Definition: Numbers Integer numbers (Integer) Integer numbers negative, zero, positive no bounds! Base functions: max, min :: Ord a => a -> a -> a (+), (-), (*), (^) :: Num a => a -> a -> a quot, rem, div, mod :: Integral a => a -> a -> a quotrem, divmod :: Integral a => a -> a -> (a, a) negate, abs, signum :: Num a => a -> a frominteger :: Num a => Integer -> a tointeger :: Integral a => a -> Integer 2015 Uwe R. Zimmer, The Australian National University page 352 of 794 (chapter 4: up to page 369)
20 Numbers Integer numbers (Integer) Definition: Integer numbers negative, zero, positive no bounds! Base functions: max, min :: Ord a => a -> a -> a (+), (-), (*), (^) :: Num a => a -> a -> a quot, rem, div, mod :: Integral a => a -> a -> a quotrem, divmod :: Integral a => a -> a -> (a, a) negate, abs, signum :: Num a => a -> a frominteger :: Num a => Integer -> a tointeger :: Integral a => a -> Integer a stands for multiple types here including Integer quot, rem truncate towards zero div, mod truncate towards negative infinity 2015 Uwe R. Zimmer, The Australian National University page 353 of 794 (chapter 4: up to page 369)
21 Numbers Ranges and Modulo Types (Ix) Definition: Sub-ranges of discrete types (Integer or enumerations), either with an out of range detection or a modulo arithmetic semantic. Not directly available in Haskell. (yet e.g. the Ix class implements part of the functionality.) Base functions: range :: Ord a => (a, a) -> [a] index :: Ord a => (a, a) -> a -> Int inrange :: Ord a => (a, a) -> a -> Bool rangesize :: Ord a => (a, a) -> Int a stands for any type on which an order is defined including Integer Example expressions: > range ( a, z ) abcdefghijklmnopqrstuvwxyz > inrange ( a, z ) b True > index ( a, z ) b 1 > range (1, 12) [1,2,3,4,5,6,7,8,9,10,11,12] Indices start at Uwe R. Zimmer, The Australian National University page 354 of 794 (chapter 4: up to page 369)
22 Numbers Ranges and Modulo Types (Ix) Definition: Sub-ranges of discrete types (Integer or enumerations), either with an out of range detection or a modulo arithmetic semantic. Not directly available in Haskell. (yet e.g. the Ix class implements part of the functionality.) Range and modulo type examples: Natural = subtype Integer range 0.. Positive = subtype Integer range 1.. Index = subtype Positive range Base_Colour = subtype Color range Red.. Blue Circular_Index = modulo 10 (none of which are natively available in Haskell) 2015 Uwe R. Zimmer, The Australian National University page 355 of 794 (chapter 4: up to page 369)
23 Numbers Rational numbers (Rational) Definition: data Integral a => Ratio a type Rational = Ratio Integer Any number defined by the ratio of two Integers no bounds or precision limits! Base functions: (%) :: Integer -> Integer -> Rational numerator :: Rational -> Integer denominator :: Rational -> Integer approxrational :: RealFrac a => a -> a -> Rational Real number which h needs converting Precision of conversion Example expressions: > 10 * (3 % 4) 15 % 2 > approxrational pi % 7 frominteger (numerator api) / frominteger (denominator api) where api = approxrational pi Uwe R. Zimmer, The Australian National University page 356 of 794 (chapter 4: up to page 369)
24 Numbers Real numbers (Float, Double) Definition: Limited precision real numbers in floating point notation (IEEE 754). - Float is stored in 32 bits (about 7 significant digits and approximate range:! 10 f10 - Double is stored in 64 bits (about 16 significant digits and approx. range:! 10 f Base functions (in addition to previously introduced numerical functions): pi :: Floating a => a exp, log, sqrt, sin, cos, tan, asin, acos, atan, sinh, cosh, tanh, asinh, acosh, atanh :: Floating a => a -> a (**), logbase, atan2 :: Floating a => a -> a -> a (^^) :: (Fractional a, Integral b) => a -> b -> a isnan, isinfinite, isdenormalized, isnegativezero, isieee :: RealFloat a => a -> Bool truncate, round, ceiling, floor :: Integral b => a -> b ). ) Uwe R. Zimmer, The Australian National University page 357 of 794 (chapter 4: up to page 369)
25 Numbers Complex numbers (Complex) Definition: data RealFloat a => Complex a = a :* a Limited precision complex numbers based on the type Float or Double for its components. Base functions (in addition to previously introduced numerical functions): realpart, imagpart, magnitude, phase :: Complex a -> a conjugate :: Complex a -> Complex a polar :: Complex a -> (a, a) mkpolar :: a -> a -> Complex a cis :: a -> Complex a 2015 Uwe R. Zimmer, The Australian National University page 358 of 794 (chapter 4: up to page 369)
26 Machine oriented scalars Words as Cardinals/Naturals (WordN) Definition: Word, Word8, Word16, Word32, Word64 are representations for words in memory interpreted as natural numbers between 0 and 2 N - 1 for WordN. Word stands for a word of default size for the local machine (size can be checked at runtime). Base functions: Functions are identical to the functions for the Integers. Warning note: Words have limited precision and all arithmetic is performed in mod 2 N. -4 :: Word (65500 :: Word16) + (40 :: Word16) 4 (65500 :: Integer) + (40 :: Integer) (65540 :: Integer) `mod` (2 ^ 16) 4 No error or warning is raised in any of those expressions in Haskell, C or Java! 2015 Uwe R. Zimmer, The Australian National University page 359 of 794 (chapter 4: up to page 369)
27 Machine oriented scalars Words as Integers (IntN) Definition: Int, Int8, Int16, Int32, Int64 are representations for words in memory interpreted as integer numbers between -2 N -1 N - and for IntN (2 s complement representation). Int has the same size as Word (size can be checked at runtime). Base functions: Functions are identical with functions for Integer. Warning note: Integers have limited precision and all arithmetic is performed in warp-around mode: (127 :: Int8) (127 :: Int8) (127 :: Integer) (((127 :: Integer) ^7) `mod` 2^8) - 2^7-128 No error or warning is raised in any of those expressions in Haskell, C or Java! 2015 Uwe R. Zimmer, The Australian National University page 360 of 794 (chapter 4: up to page 369)
28 Machine oriented scalars Bits (Bits) Definition: The type Bits is commonly used to manipulate Word or Int types on bit level. Base functions: (.&.), (..), xor :: a -> a -> a complement :: a -> a bit :: Int -> a shift, rotate, shiftl, shiftr, rotatel, rotater, setbit, clearbit, complementbit :: a -> Int -> a testbit :: a -> Int -> Bool issigned :: a -> Bool bitsize :: a -> Int Typical usages: Interface programming Efficient implementation of flag-arrays or bit-vectors Example: shift (8 :: Word8) Uwe R. Zimmer, The Australian National University page 361 of 794 (chapter 4: up to page 369)
29 Machine oriented scalars Bits (Bits) Definition: The type Bits is commonly used to manipulate Word or Int types on bit level. Base functions: (.&.), (..), xor :: a -> a -> a complement :: a -> a bit :: Int -> a shift, rotate, shiftl, shiftr, rotatel, rotater, setbit, clearbit, complementbit :: a -> Int -> a testbit :: a -> Int -> Bool issigned :: a -> Bool bitsize :: a -> Int Example: shift (8 :: Word8) 2 32 Bits type is outside the scope of this course only mentioned for completeness. Typical usages: Interface programming Efficient implementation of flag-arrays or bit-vectors 2015 Uwe R. Zimmer, The Australian National University page 362 of 794 (chapter 4: up to page 369)
30 Basic scalar types Choosing the best type In case of boolean and character types: no choice. In case of numerical types: 2015 Uwe R. Zimmer, The Australian National University page 363 of 794 (chapter 4: up to page 369)
31 Basic scalar types Choosing the best type Mathematical types: (Natural), (Positive), Integer, Rational: Can express any precision value: more_precise_pi = % No loss of precision during calculations. Behave exactly as the numbers by this name in mathematics. Versatile types: Float, Double, Complex: Limited precision, compact representation. Precision loss during calculations. Efficient calculations incl. exponential and trigonometric functions. Choice of precision. Machine oriented types: Word, Int, Bits: Most efficient calculations. Verification required that all calculations stay within limits of their types (manually or by means of automated run-time checks) Uwe R. Zimmer, The Australian National University page 364 of 794 (chapter 4: up to page 369)
32 Repetition: 1. A type name Definition An abstract type is defined by the type structure can be partly revealed or stay completely hidden and can be as simple as a character or as complicated as a database. 2. Functions / Operations which work on this type and have to follow defined rules, like an e.g. arithmetic laws or a specific algebra. What s abstract? We don t necessarily know how values are stored in memory or how the operations are implemented. All good programming interfaces are designed on a need to know basis. we can for instance use a floating point number without knowing which h bit goes where, or how the sine function is implemented 2015 Uwe R. Zimmer, The Australian National University page 365 of 794 (chapter 4: up to page 369)
33 Enumerations: Basic types Basic, scalar types overview Boolean (Bool), Characters (Char) Numbers: Cardinal (-), Integer (Integer), Integer range (Ix), Rational (Rational), Real (Float, Double), Complex (Complex) Machine related types: Bits (Bits), N Words: Integer range 0f 2-1 (Word, WordN), N- Two s complements: Integer range 2 1 N- - f (Int, IntN) with N! 2015 Uwe R. Zimmer, The Australian National University page 366 of 794 (chapter 4: up to page 369)
34 Enumerations: Basic types Basic, scalar types overview Boolean (Bool), Characters (Char) Numbers: Cardinal (-), Integer (Integer), Integer range (Ix), Rational (Rational), Real (Float, Double), Complex (Complex) Machine related types: Bits (Bits), N Words: Integer range 0f 2-1 (Word, WordN), N- Two s complements: Integer range 2 1 N- - f (Int, IntN) with N! Can you envision other abstract types? 2015 Uwe R. Zimmer, The Australian National University page 367 of 794 (chapter 4: up to page 369)
35 Enumerations: Basic types Basic, scalar types overview Boolean (Bool), Characters (Char) Numbers: Cardinal (-), Integer (Integer), Integer range (Ix), Rational (Rational), Real (Float, Double), Complex (Complex) Machine related types: Bits (Bits), Words: Integer range 0f 2 N - 1 (Word, WordN), N- Two s complements: Integer range f 2 N -1 (Int, IntN) with N! 6 Can you envision other abstract types? There will be many in fact every program can be expressed as a set of abstract types we will look into some more complex types next Uwe R. Zimmer, The Australian National University page 368 of 794 (chapter 4: up to page 369)
36 Definition What is abstract in an abstract type? Examples of abstract type Summary Boolean (Bool), Characters (Char). Numbers: Cardinal (-), Integer (Integer), Integer range (Ix), Rational (Rational), Real (Float, Double), Complex (Complex). Machine related types: Bits (Bits), Words: Integer range (Word, WordN), Two s complements Uwe R. Zimmer, The Australian National University page 369 of 794 (chapter 4: up to page 369)
Basic types and definitions. Chapter 3 of Thompson
Basic types and definitions Chapter 3 of Thompson Booleans [named after logician George Boole] Boolean values True and False are the result of tests are two numbers equal is one smaller than the other
More information1 The number systems in Haskell 98
www.bucephalus.org 1 1 The number systems in Haskell 98 1.0.1 Foreword Of all more or less popular programming languages, Haskell has the most complicated number system by far. And it is complicated from
More informationStandard prelude. Appendix A. A.1 Classes
Appendix A Standard prelude In this appendix we present some of the most commonly used definitions from the standard prelude. For clarity, a number of the definitions have been simplified or modified from
More informationHaskell Programs. Haskell Fundamentals. What are Types? Some Very Basic Types. Types are very important in Haskell:
Haskell Programs We re covering material from Chapters 1-2 (and maybe 3) of the textbook. Haskell Fundamentals Prof. Susan Older A Haskell program is a series of comments and definitions. Each comment
More informationInformatics 1 Functional Programming Lecture 5. Function properties. Don Sannella University of Edinburgh
Informatics 1 Functional Programming Lecture 5 Function properties Don Sannella University of Edinburgh Part I Booleans and characters Boolean operators not :: Bool -> Bool (&&), ( ) :: Bool -> Bool ->
More informationA tour of the Haskell Prelude
A tour of the Haskell Prelude Bernie Pope 2001 1 Haskell The Haskell language was conceived during a meeting held at the 1987 Functional Programming and Computer Architecture conference (FPCA 87). At the
More informationBuilt-in Types of Data
Built-in Types of Data Types A data type is set of values and a set of operations defined on those values Python supports several built-in data types: int (for integers), float (for floating-point numbers),
More informationArithmetic and Logic Blocks
Arithmetic and Logic Blocks The Addition Block The block performs addition and subtractions on its inputs. This block can add or subtract scalar, vector, or matrix inputs. We can specify the operation
More informationEDAF40. 2nd June :00-19:00. WRITE ONLY ON ONE SIDE OF THE PAPER - the exams will be scanned in and only the front/ odd pages will be read.
EDAF40 2nd June 2017 14:00-19:00 WRITE ONLY ON ONE SIDE OF THE PAPER - the exams will be scanned in and only the front/ odd pages will be read. DO NOT WRITE WITH OTHER COLOUR THAN BLACK - coloured text
More informationCSc 372. Comparative Programming Languages. 4 : Haskell Basics. Department of Computer Science University of Arizona
1/40 CSc 372 Comparative Programming Languages 4 : Haskell Basics Department of Computer Science University of Arizona collberg@gmail.com Copyright c 2013 Christian Collberg 2/40 The Hugs Interpreter The
More informationCSc 372 Comparative Programming Languages. 4 : Haskell Basics
CSc 372 Comparative Programming Languages 4 : Haskell Basics Christian Collberg Department of Computer Science University of Arizona collberg@gmail.com Copyright c 2011 Christian Collberg August 23, 2011
More informationPython. Olmo Zavala R. Python Exercises. Center of Atmospheric Sciences, UNAM. August 24, 2016
Exercises Center of Atmospheric Sciences, UNAM August 24, 2016 NAND Make function that computes the NAND. It should receive two booleans and return one more boolean. logical operators A and B, A or B,
More informationMentor Graphics Predefined Packages
Mentor Graphics Predefined Packages Mentor Graphics has created packages that define various types and subprograms that make it possible to write and simulate a VHDL model within the Mentor Graphics environment.
More informationComputing Fundamentals
Computing Fundamentals Salvatore Filippone salvatore.filippone@uniroma2.it 2012 2013 (salvatore.filippone@uniroma2.it) Computing Fundamentals 2012 2013 1 / 18 Octave basics Octave/Matlab: f p r i n t f
More informationType system. Type theory. Haskell type system. EDAN40: Functional Programming Types and Type Classes (revisited)
Type system EDAN40: Functional Programming Types and Type Classes (revisited) Jacek Malec Dept. of Computer Science, Lund University, Sweden April 3rd, 2017 In programming languages, a type system is a
More informationCSc 520. Principles of Programming Languages 11: Haskell Basics
CSc 520 Principles of Programming Languages 11: Haskell Basics Christian Collberg Department of Computer Science University of Arizona collberg@cs.arizona.edu Copyright c 2005 Christian Collberg April
More informationComputer Science 121. Scientific Computing Winter 2016 Chapter 3 Simple Types: Numbers, Text, Booleans
Computer Science 121 Scientific Computing Winter 2016 Chapter 3 Simple Types: Numbers, Text, Booleans 3.1 The Organization of Computer Memory Computers store information as bits : sequences of zeros and
More informationRecursion and Induction: Haskell; Primitive Data Types; Writing Function Definitions
Recursion and Induction: Haskell; Primitive Data Types; Writing Function Definitions Greg Plaxton Theory in Programming Practice, Spring 2005 Department of Computer Science University of Texas at Austin
More informationFunctional Programming TDA 452, DIT 142
Chalmers Göteborgs Universitet 2016-04-07 Examiner: David Sands dave@chalmers.se. Answering questions on the day of the exam (at approx 15.00): Gregoire Detrez (tel: 073 55 69 550) and at other times by
More informationMatlab Workshop I. Niloufer Mackey and Lixin Shen
Matlab Workshop I Niloufer Mackey and Lixin Shen Western Michigan University/ Syracuse University Email: nil.mackey@wmich.edu, lshen03@syr.edu@wmich.edu p.1/13 What is Matlab? Matlab is a commercial Matrix
More informationOverview. Declarative Languages D7012E. Overloading. Overloading Polymorphism Subtyping
Overview Declarative Languages D7012E Lecture 4: The Haskell type system Fredrik Bengtsson / Johan Nordlander Overloading & polymorphism Type classes instances of type classes derived type classes Type
More informationHow to Design Programs Languages
How to Design Programs Languages Version 4.1 August 12, 2008 The languages documented in this manual are provided by DrScheme to be used with the How to Design Programs book. 1 Contents 1 Beginning Student
More information1001ICT Introduction To Programming Lecture Notes
1001ICT Introduction To Programming Lecture Notes School of Information and Communication Technology Griffith University Semester 1, 2015 1 M Environment console M.1 Purpose This environment supports programming
More informationFUNCTIONAL PROGRAMMING NO.9 TYPE AND CLASS. Tatsuya Hagino
1 FUNCTIONAL PROGRAMMING NO.9 TYPE AND CLASS Tatsuya Hagino hagino@sfc.keio.ac.jp 2 Static Type Checking and Type Inference Type a set of values Bool = { True, False } Char = { 'a', 'b',... } Int = {...
More informationHaskell Modules. Input and Output. Urtė Zubkaitė
Haskell Modules. Input and Output Urtė Zubkaitė Modules in Haskell A Haskell program is a collection of modules where the main module loads up the other modules and then uses the functions defined in them
More informationUsing the um-fpu with the Javelin Stamp
Using the um-fpu with the Javelin Stamp Introduction The um-fpu is a 32-bit floating point coprocessor that can be easily interfaced with the Javelin Stamp to provide support for 32-bit IEEE 754 floating
More informationAbstract Types, Algebraic Types, and Type Classes
Informatics 1 Functional Programming Lectures 13 and 14 Monday 9 and Tuesday 10 November 2009 Abstract Types, Algebraic Types, and Type Classes Philip Wadler University of Edinburgh Reminders Tutorial
More informationCS 320: Concepts of Programming Languages
CS 320: Concepts of Programming Languages Wayne Snyder Computer Science Department Boston University Lecture 08: Type Classes o o Review: What is a type class? Basic Type Classes: Eq, Ord, Enum, Integral,
More informationSimple Animations. Today s Topics. Reading Assignment
Today s Topics Simple Animations Simple animations Buffered graphics Animations in Haskell Complex animations Lifting primitives to animations Behaviors Type classes, animations, and Behaviors Time translation
More informationBits, Words, and Integers
Computer Science 52 Bits, Words, and Integers Spring Semester, 2017 In this document, we look at how bits are organized into meaningful data. In particular, we will see the details of how integers are
More informationMATLAB Constants, Variables & Expression. 9/12/2015 By: Nafees Ahmed
MATLAB Constants, Variables & Expression Introduction MATLAB can be used as a powerful programming language. It do have IF, WHILE, FOR lops similar to other programming languages. It has its own vocabulary
More informationScript started on Thu 25 Aug :00:40 PM CDT
Script started on Thu 25 Aug 2016 02:00:40 PM CDT < M A T L A B (R) > Copyright 1984-2014 The MathWorks, Inc. R2014a (8.3.0.532) 64-bit (glnxa64) February 11, 2014 To get started, type one of these: helpwin,
More informationMain Program. C Programming Notes. #include <stdio.h> main() { printf( Hello ); } Comments: /* comment */ //comment. Dr. Karne Towson University
C Programming Notes Dr. Karne Towson University Reference for C http://www.cplusplus.com/reference/ Main Program #include main() printf( Hello ); Comments: /* comment */ //comment 1 Data Types
More informationFunctional Programming TDA 452, DIT 142
Chalmers Göteborgs Universitet 2018-01-11 Examiner: Thomas Hallgren, D&IT, Answering questions at approx 15.00 (or by phone) Functional Programming TDA 452, DIT 142 2018-01-11 14.00 18.00 Samhällsbyggnad
More informationComputing and Statistical Data Analysis Lecture 3
Computing and Statistical Data Analysis Lecture 3 Type casting: static_cast, etc. Basic mathematical functions More i/o: formatting tricks Scope, namspaces Functions 1 Type casting Often we need to interpret
More informationAdvanced features of Functional Programming (Haskell)
Advanced features of Functional Programming (Haskell) Polymorphism and overloading January 10, 2017 Monomorphic and polymorphic types A (data) type specifies a set of values. Examples: Bool: the type of
More informationFunctional Programming I *** Functional Programming and Interactive Theorem Proving. Ulrich Berger Michaelmas Term 2006
Functional Programming I *** Functional Programming and Interactive Theorem Proving Ulrich Berger Michaelmas Term 2006 2 *** Room 306 (Faraday Tower) Phone 513380 Fax 295708 u.berger@swansea.ac.uk http://www-compsci.swan.ac.uk/
More informationFuncons. reusable components of language specifications. Peter D. Mosses. Swansea University (emeritus) TU Delft (visitor)
Funcons reusable components of language specifications Peter D. Mosses Swansea University (emeritus) TU Delft (visitor) LangDev Meet-Up at CWI, Amsterdam, 8 9 March 2018 Contents Motivation 3 Funcons 7
More informationCS-201 Introduction to Programming with Java
CS-201 Introduction to Programming with Java California State University, Los Angeles Computer Science Department Lecture V: Mathematical Functions, Characters, and Strings Introduction How would you estimate
More informationIntroduction to Programming, Aug-Dec 2008
Introduction to Programming, Aug-Dec 2008 Lecture 1, Monday 4 Aug 2008 Administrative matters Resource material Textbooks and other resource material for the course: The Craft of Functional Programming
More informationBasic operators, Arithmetic, Relational, Bitwise, Logical, Assignment, Conditional operators. JAVA Standard Edition
Basic operators, Arithmetic, Relational, Bitwise, Logical, Assignment, Conditional operators JAVA Standard Edition Java - Basic Operators Java provides a rich set of operators to manipulate variables.
More informationModule 01: Introduction to Programming in Python
Module 01: Introduction to Programming in Python Topics: Course Introduction Introduction to Python basics Readings: ThinkP 1,2,3 1 Finding course information https://www.student.cs.uwaterloo.ca/~cs116/
More informationInformatics 1 Functional Programming Lectures 13 and 14 Monday 11 and Tuesday 12 November Type Classes. Don Sannella University of Edinburgh
Informatics 1 Functional Programming Lectures 13 and 14 Monday 11 and Tuesday 12 November 2013 Type Classes Don Sannella University of Edinburgh Mock exam Slots and rooms have now been assigned Mon 18
More informationLAB 1 General MATLAB Information 1
LAB 1 General MATLAB Information 1 General: To enter a matrix: > type the entries between square brackets, [...] > enter it by rows with elements separated by a space or comma > rows are terminated by
More informationZheng-Liang Lu Java Programming 45 / 79
1 class Lecture2 { 2 3 "Elementray Programming" 4 5 } 6 7 / References 8 [1] Ch. 2 in YDL 9 [2] Ch. 2 and 3 in Sharan 10 [3] Ch. 2 in HS 11 / Zheng-Liang Lu Java Programming 45 / 79 Example Given a radius
More informationChapter 4. Operations on Data
Chapter 4 Operations on Data 1 OBJECTIVES After reading this chapter, the reader should be able to: List the three categories of operations performed on data. Perform unary and binary logic operations
More informationAdvanced features of the Calculate signal tool
Advanced features of the Calculate signal tool Case study: how to us the advanced features of the Calculate signal tool? 1 The calculate signal tool The calculate signal tool is one of the most useful
More informationTYPES, VALUES AND DECLARATIONS
COSC 2P90 TYPES, VALUES AND DECLARATIONS (c) S. Thompson, M. Winters 1 Names, References, Values & Types data items have a value and a type type determines set of operations variables Have an identifier
More informationCSC312 Principles of Programming Languages : Functional Programming Language. Copyright 2006 The McGraw-Hill Companies, Inc.
CSC312 Principles of Programming Languages : Functional Programming Language Overview of Functional Languages They emerged in the 1960 s with Lisp Functional programming mirrors mathematical functions:
More information1 class Lecture2 { 2 3 "Elementray Programming" / References 8 [1] Ch. 2 in YDL 9 [2] Ch. 2 and 3 in Sharan 10 [3] Ch.
1 class Lecture2 { 2 3 "Elementray Programming" 4 5 } 6 7 / References 8 [1] Ch. 2 in YDL 9 [2] Ch. 2 and 3 in Sharan 10 [3] Ch. 2 in HS 11 / Zheng-Liang Lu Java Programming 41 / 68 Example Given the radius
More informationIntroduction to Programming: Lecture 10
Introduction to Programming: Lecture 10 K Narayan Kumar Chennai Mathematical Institute http://www.cmi.ac.in/~kumar 10 Sep 2012 Organizing functions as Modules Organize functions into modules. Organizing
More information4 Operations On Data 4.1. Foundations of Computer Science Cengage Learning
4 Operations On Data 4.1 Foundations of Computer Science Cengage Learning Objectives After studying this chapter, the student should be able to: List the three categories of operations performed on data.
More informationAdvanced Algorithms and Computational Models (module A)
Advanced Algorithms and Computational Models (module A) Giacomo Fiumara giacomo.fiumara@unime.it 2014-2015 1 / 34 Python's built-in classes A class is immutable if each object of that class has a xed value
More informationPROGRAMMING IN HASKELL. Chapter 5 - List Comprehensions
PROGRAMMING IN HASKELL Chapter 5 - List Comprehensions 0 Set Comprehensions In mathematics, the comprehension notation can be used to construct new sets from old sets. {x 2 x {1...5}} The set {1,4,9,16,25}
More informationThe Design of C: A Rational Reconstruction"
The Design of C: A Rational Reconstruction 1 Goals of this Lecture Help you learn about: The decisions that were available to the designers of C The decisions that were made by the designers of C and thereby
More informationInf2C - Computer Systems Lecture 2 Data Representation
Inf2C - Computer Systems Lecture 2 Data Representation Boris Grot School of Informatics University of Edinburgh Last lecture Moore s law Types of computer systems Computer components Computer system stack
More information6.034 Artificial Intelligence February 9, 2007 Recitation # 1. (b) Draw the tree structure corresponding to the following list.
6.034 Artificial Intelligence February 9, 2007 Recitation # 1 1 Lists and Trees (a) You are given two lists: (define x (list 1 2 3)) (define y (list 4 5 6)) What would the following evaluate to: (append
More informationComputer Architecture and System Software Lecture 02: Overview of Computer Systems & Start of Chapter 2
Computer Architecture and System Software Lecture 02: Overview of Computer Systems & Start of Chapter 2 Instructor: Rob Bergen Applied Computer Science University of Winnipeg Announcements Website is up
More informationChapter 15. Functional Programming. Topics. Currying. Currying: example. Currying: example. Reduction
Topics Chapter 15 Functional Programming Reduction and Currying Recursive definitions Local definitions Type Systems Strict typing Polymorphism Classes Booleans Characters Enumerations Tuples Strings 2
More informationLecture Notes on Haskell Programming
Lecture Notes on Haskell Programming Luca Padovani Istituto di Scienze e Tecnologie dell Informazione Università di Urbino Carlo Bo ii Generated on February 12, 2010 Comments, suggestions for improving
More informationExercise: Using Numbers
Exercise: Using Numbers Problem: You are a spy going into an evil party to find the super-secret code phrase (made up of letters and spaces), which you will immediately send via text message to your team
More informationArithmetic and Bitwise Operations on Binary Data
Arithmetic and Bitwise Operations on Binary Data CSCI 2400: Computer Architecture ECE 3217: Computer Architecture and Organization Instructor: David Ferry Slides adapted from Bryant & O Hallaron s slides
More informationA. Matrix-wise and element-wise operations
USC GSBME MATLAB CLASS Reviewing previous session Second session A. Matrix-wise and element-wise operations A.1. Matrix-wise operations So far we learned how to define variables and how to extract data
More informationLecture 2 FORTRAN Basics. Lubna Ahmed
Lecture 2 FORTRAN Basics Lubna Ahmed 1 Fortran basics Data types Constants Variables Identifiers Arithmetic expression Intrinsic functions Input-output 2 Program layout PROGRAM program name IMPLICIT NONE
More informationHaskell An Introduction
Haskell An Introduction What is Haskell? General purpose Purely functional No function can have side-effects IO is done using special types Lazy Strongly typed Polymorphic types Concise and elegant A First
More informationObject-Based Programming. Programming with Objects
ITEC1620 Object-Based Programming g Lecture 8 Programming with Objects Review Sequence, Branching, Looping Primitive datatypes Mathematical operations Four-function calculator Scientific calculator Don
More informationLecture Notes on Ints
Lecture Notes on Ints 15-122: Principles of Imperative Computation Frank Pfenning Lecture 2 August 26, 2010 1 Introduction Two fundamental types in almost any programming language are booleans and integers.
More informationUser-Defined Algebraic Data Types
72 Static Semantics User-Defined Types User-Defined Algebraic Data Types An algebraic data type declaration has the general form: data cx T α 1... α k = K 1 τ 11... τ 1k1... K n τ n1... τ nkn introduces
More informationBasics of ST. Each must end with a semi-colon (";") Basic statement. Q:=IN; Q:=sin(angle); Q := (IN1 + (IN2 / IN 3)) * IN4;
Excerpt of tutorial developed at University of Auckland by Gulnara Zhabelova Based on Dr. Valeriy Vyatkin s book IEC 61499 Function Blocks for Embedded and Distributed Control Systems Design, Second Edition
More informationFunctional Programming Languages (FPL)
Functional Programming Languages (FPL) 1. Definitions... 2 2. Applications... 2 3. Examples... 3 4. FPL Characteristics:... 3 5. Lambda calculus (LC)... 4 6. Functions in FPLs... 7 7. Modern functional
More informationMuntaser Abulafi Yacoub Sabatin Omar Qaraeen. C Data Types
Programming Fundamentals for Engineers 0702113 5. Basic Data Types Muntaser Abulafi Yacoub Sabatin Omar Qaraeen 1 2 C Data Types Variable definition C has a concept of 'data types' which are used to define
More informationIt is better to have 100 functions operate one one data structure, than 10 functions on 10 data structures. A. Perlis
Chapter 14 Functional Programming Programming Languages 2nd edition Tucker and Noonan It is better to have 100 functions operate one one data structure, than 10 functions on 10 data structures. A. Perlis
More informationLogic, Words, and Integers
Computer Science 52 Logic, Words, and Integers 1 Words and Data The basic unit of information in a computer is the bit; it is simply a quantity that takes one of two values, 0 or 1. A sequence of k bits
More informationCS3157: Advanced Programming. Outline
CS3157: Advanced Programming Lecture #8 Feb 27 Shlomo Hershkop shlomo@cs.columbia.edu 1 Outline More c Preprocessor Bitwise operations Character handling Math/random Review for midterm Reading: k&r ch
More informationPractical Haskell. An introduction to functional programming. July 21, Practical Haskell. Juan Pedro Villa-Isaza. Introduction.
Practical Practical An introduction to functional programming July 21, 2011 Contents Practical Practical is fun, and that s what it s all about! Even if seems strange to you at first, don t give up. Learning
More informationWhy Don t Computers Use Base 10? Lecture 2 Bits and Bytes. Binary Representations. Byte-Oriented Memory Organization. Base 10 Number Representation
Lecture 2 Bits and Bytes Topics Why bits? Representing information as bits Binary/Hexadecimal Byte representations» numbers» characters and strings» Instructions Bit-level manipulations Boolean algebra
More informationcs3157: another C lecture (mon-21-feb-2005) C pre-processor (3).
cs3157: another C lecture (mon-21-feb-2005) C pre-processor (1). today: C pre-processor command-line arguments more on data types and operators: booleans in C logical and bitwise operators type conversion
More informationThe Design of C: A Rational Reconstruction
The Design of C: A Rational Reconstruction 1 Goals of this Lecture Help you learn about: The decisions that were available to the designers of C The decisions that were made by the designers of C and thereby
More informationCIS 194: Homework 4. Due Wednesday, February 18, What is a Number?
CIS 194: Homework 4 Due Wednesday, February 18, 2015 What is a Number? This may sound like a deep, philosophical question, but the Haskell type system gives us a simple way to answer it. A number is any
More informationA General Introduction to Matlab
Master Degree Course in ELECTRONICS ENGINEERING http://www.dii.unimore.it/~lbiagiotti/systemscontroltheory.html A General Introduction to Matlab e-mail: luigi.biagiotti@unimore.it http://www.dii.unimore.it/~lbiagiotti
More informationTopic 1: Introduction
Recommended Exercises and Readings Topic 1: Introduction From Haskell: The craft of functional programming (3 rd Ed.) Readings: Chapter 1 Chapter 2 1 2 What is a Programming Paradigm? Programming Paradigm:
More informationWhy Don t Computers Use Base 10? Lecture 2 Bits and Bytes. Binary Representations. Byte-Oriented Memory Organization. Base 10 Number Representation
Lecture 2 Bits and Bytes Topics! Why bits?! Representing information as bits " Binary/Hexadecimal " Byte representations» numbers» characters and strings» Instructions! Bit-level manipulations " Boolean
More informationIntroduction to Scientific and Engineering Computing, BIL108E. Karaman
USING MATLAB INTRODUCTION TO SCIENTIFIC & ENGINEERING COMPUTING BIL 108E, CRN24023 To start from Windows, Double click the Matlab icon. To start from UNIX, Dr. S. Gökhan type matlab at the shell prompt.
More informationCS 320: Concepts of Programming Languages
CS 320: Concepts of Programming Languages Wayne Snyder Computer Science Department Boston University Lecture 06: Useful Haskell Syntax, HO Programming Continued o Goodbye to Bare Bones Haskell: Built-in
More informationCOSC 243. Data Representation 3. Lecture 3 - Data Representation 3 1. COSC 243 (Computer Architecture)
COSC 243 Data Representation 3 Lecture 3 - Data Representation 3 1 Data Representation Test Material Lectures 1, 2, and 3 Tutorials 1b, 2a, and 2b During Tutorial a Next Week 12 th and 13 th March If you
More informationCSCI2467: Systems Programming Concepts
CSCI2467: Systems Programming Concepts Slideset 2: Information as Data (CS:APP Chap. 2) Instructor: M. Toups Spring 2018 Course updates datalab out today! - due after Mardi gras... - do not wait until
More informationThe Design of C: A Rational Reconstruction" Jennifer Rexford!
The Design of C: A Rational Reconstruction" Jennifer Rexford! 1 Goals of this Lecture"" Number systems! Binary numbers! Finite precision! Binary arithmetic! Logical operators! Design rationale for C! Decisions
More informationContents. Preface. Introduction. Introduction to C Programming
c11fptoc.fm Page vii Saturday, March 23, 2013 4:15 PM Preface xv 1 Introduction 1 1.1 1.2 1.3 1.4 1.5 Introduction The C Programming Language C Standard Library C++ and Other C-Based Languages Typical
More informationOperators and Expressions in C & C++ Mahesh Jangid Assistant Professor Manipal University, Jaipur
Operators and Expressions in C & C++ Mahesh Jangid Assistant Professor Manipal University, Jaipur Operators and Expressions 8/24/2012 Dept of CS&E 2 Arithmetic operators Relational operators Logical operators
More informationMacro Programming Reference Guide. Copyright 2005 Scott Martinez
Macro Programming Reference Guide Copyright 2005 Scott Martinez Section 1. Section 2. Section 3. Section 4. Section 5. Section 6. Section 7. What is macro programming What are Variables What are Expressions
More informationLimits. f(x) and lim. g(x) g(x)
Limits Limit Laws Suppose c is constant, n is a positive integer, and f() and g() both eist. Then,. [f() + g()] = f() + g() 2. [f() g()] = f() g() [ ] 3. [c f()] = c f() [ ] [ ] 4. [f() g()] = f() g()
More informationVariables. location where in memory is the information stored type what sort of information is stored in that memory
Variables Processing, like many programming languages, uses variables to store information Variables are stored in computer memory with certain attributes location where in memory is the information stored
More informationJava enum, casts, and others (Select portions of Chapters 4 & 5)
Enum or enumerates types Java enum, casts, and others (Select portions of Chapters 4 & 5) Sharma Chakravarthy Information Technology Laboratory (IT Lab) Computer Science and Engineering Department The
More informationStarting MATLAB To logon onto a Temple workstation at the Tech Center, follow the directions below.
What is MATLAB? MATLAB (short for MATrix LABoratory) is a language for technical computing, developed by The Mathworks, Inc. (A matrix is a rectangular array or table of usually numerical values.) MATLAB
More informationLong (or LONGMATH ) floating-point (or integer) variables (length up to 1 million, limited by machine memory, range: approx. ±10 1,000,000.
QuickCalc User Guide. Number Representation, Assignment, and Conversion Variables Constants Usage Double (or DOUBLE ) floating-point variables (approx. 16 significant digits, range: approx. ±10 308 The
More informationArcGIS Enterprise Building Raster Analytics Workflows. Mike Muller, Jie Zhang
ArcGIS Enterprise Building Raster Analytics Workflows Mike Muller, Jie Zhang Introduction and Context Raster Analytics What is Raster Analytics? The ArcGIS way to create and execute spatial analysis models
More informationRepresenting numbers on the computer. Computer memory/processors consist of items that exist in one of two possible states (binary states).
Representing numbers on the computer. Computer memory/processors consist of items that exist in one of two possible states (binary states). These states are usually labeled 0 and 1. Each item in memory
More informationProgramming Languages Fall 2013
Programming Languages Fall 2013 Lecture 2: types Prof. Liang Huang huang@qc.cs.cuny.edu Recap of Lecture 1 functional programming vs. imperative programming basic Haskell syntax function definition lazy
More informationComputer Programming 5th Week loops (do-while, for), Arrays, array operations, C libraries
Computer Programming 5th Week loops (do-while, for), Arrays, array operations, C libraries Hazırlayan Asst. Prof. Dr. Tansu Filik Computer Programming Previously on Bil 200 Low-Level I/O getchar, putchar,
More informationCOMP Primitive and Class Types. Yi Hong May 14, 2015
COMP 110-001 Primitive and Class Types Yi Hong May 14, 2015 Review What are the two major parts of an object? What is the relationship between class and object? Design a simple class for Student How to
More information