CSCE 314 Programming Languages - Texas A&M University
Lee CSCE 314 TAMU
CSCE 314
Programming Languages
Haskell: Types, Classes, Functions, Currying and Polymorphism
Dr. Hyunyoung Lee
1
Lee CSCE 314 TAMU
Types
A type is a collection of related values. For example,
Bool contains the two logical values True and False
Int contains values -229, ..., -1, 0, 1, ..., 229 -1
If evaluating an expression e would produce a value of type t, then e has type T, written
e :: T
Every well formed expression has a type, which can be automatically calculated at compile time using a process called type inference.
2
Type Errors
Lee CSCE 314 TAMU
Applying a function to one or more arguments of the wrong type is called a type error.
> 1 + False Error
1 is a number and False is a logical value, but + requires two numbers
.
Static type checking: all type errors are found at compile time, which makes programs safer and faster by removing the need for type checks at run time.
3
Lee CSCE 314 TAMU
Type Annotations
Programmer can (and at times must) annotate expressions with type in the form
e :: T
For example,
True :: Bool
5 :: Int
-- type is really (Num t) => t
(5 + 5) :: Int
-- likewise
(7 < 8) :: Bool
Some expressions can have many types, e.g.,
5 :: Int, 5 :: Integer, 5 :: Float
GHCi command :type e shows
> not False True
the type of (the result of) e
> :type not False not False :: Bool
4
Lee CSCE 314 TAMU
Basic Types
Haskell has a number of basic types, including:
Bool Char
- logical values
- single characters
String - lists of characters type String = [Char]
Int Integer
- fixed-precision integers
- arbitrary-precision integers
Float Double
- single-precision floating-point numbers
- double-precision floating-point numbers
5
................
................
In order to avoid copyright disputes, this page is only a partial summary.
To fulfill the demand for quickly locating and searching documents.
It is intelligent file search solution for home and business.
Related download
- csce 314 programming languages texas a m university
- programming in haskell
- haskell tutorial
- hvx disciplined convex programming and symbolic subdi
- a general introduction to functional programming using haskell
- 1 the number systems in haskell 98
- ieee visweek tutorial 2008 lexical syntax haskell
- data types computer science
- richard a eisenberg simon peyton jones
- hapy haskell for python
Related searches
- texas a m money education center
- texas a m grading scale
- texas a m 2020 2021 academic schedule
- texas a m extension child care training
- texas a m academic calendar
- texas a m 1098 t
- texas a m campuses in texas
- texas a m financial aid portal
- texas a m university campuses
- texas a m online engineering degree
- texas a m online engineering masters
- texas a m college station tuition