!
List index (subscript) operator, starting from 0. It is an instance of the more general Data.List.genericIndex, which takes an index of any integral type.
O(min(n,W)). Find the value at a key. Calls error when the element can not be found.
> fromList [(5,'a'), (3,'b')] ! 1 Error: element not in the map
> fromList [(5,'a'), (3,'b')] ! 5 == 'a'
Returns the element of an immutable array at the specified index.
The value at the given index in an array.
O(log n). Find the value at a key. Calls error when the element can not be found.
> fromList [(5,'a'), (3,'b')] ! 1 Error: element not in the map
> fromList [(5,'a'), (3,'b')] ! 5 == 'a'
Whenever a data constructor is applied, each argument to the constructor is evaluated if and only if the corresponding type in the algebraic datatype declaration has a strictness flag, denoted by an exclamation point. For example:
> data STList a
> = STCons a !(STList a) -- the second argument to STCons will be
> -- evaluated before STCons is applied
> | STNil
to illustrate the difference between strict versus lazy constructor application, consider the following:
> stList = STCons 1 undefined
> lzList = (:) 1 undefined
> stHead (STCons h _) = h -- this evaluates to undefined when applied to stList
> lzHead (h : _) = h -- this evaluates to 1 when applied to lzList
! is also used in the "bang patterns" (GHC extension), to indicate strictness in patterns:
> f !x !y = x + y
Strict (call-by-value) application, defined in terms of seq.
the deep analogue of $!. In the expression f $!! x, x is fully evaluated before the function f is applied to it.