PROGRAMMING IN HASKELL
PROGRAMMING IN HASKELL
Chapter 8 - Declaring Types and Classes
0
Type Declarations
In Haskell, a new name for an existing type can be
defined using a type declaration.
type String = [Char]
String is a synonym for the type [Char].
1
Type declarations can be used to make other types
easier to read. For example, given
type Pos = (Int,Int)
we can define:
origin :: Pos
origin = (0,0)
left :: Pos ? Pos
left (x,y) = (x-1,y)
2
Like function definitions, type declarations can also
have parameters. For example, given
type Pair a = (a,a)
we can define:
mult :: Pair Int ? Int
mult (m,n) = m*n
copy :: a ? Pair a
copy x = (x,x)
3
Type declarations can be nested:
type Pos = (Int,Int)
type Trans = Pos ? Pos
However, they cannot be recursive:
type Tree = (Int,[Tree])
4
................
................
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
- macro programming in excel
- programming in excel
- programming in java pdf
- programming in matlab
- object oriented programming in matlab
- programming in basic
- database programming in java
- database programming in python
- object oriented programming in python
- python programming in visual studio
- python programming in linux
- haskell convert int to integer