index
Lib.index : ('a -> bool) -> 'a list -> int
Finds index of first list element for which predicate holds.
An application index P l returns the index (0-based) to the first
element (in a left-to-right scan) of l that P holds of.
Failure
If P doesn't hold of any element of l, then index P l fails. If
P x fails for any x encountered in the scan, then index P l fails.
Example
> index (equal 3) [1,2,3];
val it = 2: int
> let fun even i = (i mod 2 = 0)
in try (index even) [1,3,5,7,9]
end;
Exception- Type error in function application.
Function: try (index even) :
(int -> int list option) list -> int -> int
Argument: [1, 3, 5, 7, 9] : int list
Reason:
Can't unify int to int -> int list option (Incompatible types)
Fail "Static Errors" raised
> index (equal 3 o hd) [[1],[],[2,3]];
Exception- Empty raised