ZVON > References > Haskell reference
| Indexes | Syntax | Prelude | Ratio | Complex | Numeric | Ix | >> Array << | List | Maybe | Char | Monad | IO | Directory | System | Time | Locale | CPUTime | Random

Module: Array
Function: array
Type: Ix a => (a,a) -> [(a,b)] -> Array a b
Description:

If a is an index type and b is any type, the type of arrays with indices in a and elements in b is written Array a b. An array may be created by the function array. The first argument of array is a pair of bounds, each of the index type of the array. These bounds are the lowest and highest indices in the array, in that order. For example, a one-origin vector of length 10 has bounds (1,10), and a one-origin 10 by 10 matrix has bounds ((1,1),(10,10)).

The second argument of array is a list of associations of the form (index, value). Typically, this list will be expressed as a comprehension. An association (i, x) defines the value of the array at index i to be x. The array is undefined (i.e. _|_) if any index in the list is out of bounds. If any two associations in the list have the same index, the value at that index is undefined (i.e. _|_). Because the indices must be checked for these errors, array is strict in the bounds argument and in the indices of the association list, but nonstrict in the values.

Not every index within the bounds of the array need appear in the association list, but the values associated with indices that do not appear will be undefined.

Related: accumArray, listArray

Example 1

Input: array (1,3) [(1,1),(2,5),(3,6)] ! 2

Output: 5

Example 2

Input: array (0,3) [(1,"A"),(2,"B"),(3,"D"),(0,"QQQ")]

Output: array (0,3) [(0,"QQQ"),(1,"A"),(2,"B"),(3,"D")]

Example 3

Input: array (1,10) (zip [1..10] [5,9..100])

Output: array (1,10) [(1,5),(2,9),(3,13),(4,17),(5,21),(6,25),(7,29),(8,33),(9,37),(10,41)]

Example 4
Program source: 

import Array

a = array (1,10) ((1,1) : [(i, i * a!(i-1)) | i <- [2..10]])

Input: a

Output: array (1,10) [(1,1),(2,2),(3,6),(4,24),(5,120),(6,720),(7,5040),(8,40320),(9,362880),(10,3628800)]

Example 5

Input: array ((1,1),(2,2)) [((2,1),"C"),((1,2),"B"),((1,1),"A"),((2,2),"D")]

Output: array ((1,1),(2,2)) [((1,1),"A"),((1,2),"B"),((2,1),"C"),((2,2),"D")]

Example 6

Input: array ((1,1),(2,2)) [((2,1),"C"),((1,2),"B"),((1,1),"A"),((2,2),"D")] ! (2,2)

Output: "D"

Example 7

Input: array ('a','c') [('a',"AAA"),('b',"BBB"),('c',"CCC")] ! 'b'

Output: "BBB"




_____________________________________________
Reference Search | Sitemap | XML Glossary       ZVON | Systinet




Related sites:
  • dotNet Slackers - Your latest resource for ASP.NET
  • Dotnet Spider - Outsourcing and Offshore software development in India
  • XML - Xselerator, XSL Editor, BizTalk Utilities, XML Tutorials, Learn XML
  • Planet Source Code - The largest public source code database on the Internet
UNLIMITED Web Hosting by HostDepartment Alojamiento Web UK Domain Names glossary for conference call answering service
MSN VoIP Internettelefonie Hosted Exchange, SDSL VoIP Internettelefonie AT VoIP Internettelefonie DE