According to your example, you simply call your qsort with the appropriate list of unsorted values and get a sorted list:
some_useful_fun(X, Y) -> % ... Xsorted = qsort(X), % do something with Xsorted ...
And it's all. In pure functional programming, there is no state. The only state is the data passed as arguments to the functions. It is assumed that the function returns the same result for the arguments passed, regardless of how many times you call it.
In Erlang, you can map your object to a record. Consider this code:
-export([sort/0]). -record(person, { name, age }). persons_list() -> [ #person{name="John", age=38}, #person{name="Paul", age=25}, #person{name="Michael", age=23} ]. qsort(_Pred1, _Pred2, []) -> []; qsort(Pred1, Pred2, [Pivot|T]) -> qsort(Pred1, Pred2, [X || X <- T, Pred1(X, Pivot)]) ++ [Pivot] ++ qsort(Pred2, Pred2, [X || X <- T, Pred2(X, Pivot)]). sort() -> F1 = fun(#person{age = A1}, #person{age = A2}) -> A1 =< A2 end, F2 = fun(#person{age = A1}, #person{age = A2}) -> A1 > A2 end, qsort(F1, F2, persons_list()).
We have a person entry that has two fields, especially name and age . We also have two predicates F1 and F2 that correspond to what qsort does. If we now call qsort/3 with these two predicates and a list of person entries, we get the following results:
1> c(persons). {ok,persons} 2> persons:sort(). [{person,"Michael",23}, {person,"Paul",25}, {person,"John",38}] 3>
What is a sorted list of person entries, then you can use it in your code.