The base case for this function occurs when the list is empty. If it is not then there are two sub-cases.
fun takewhile (p, []) = [] | takewhile (p, h::t) = if p h then h :: takewhile (p, t) else [];
Exercise
Construct the analogous dropwhile function.
Exercise
Construct a filter function which returns all the elements of a list which satisfy a given predicate.