syntax

Kurt Wilkin <>
Fri Jan 28 01:24:34 CET 2000


Hello all.

I recently read this version of selection sort in a Haskell
algorithms book (from memory):

selsort [] = []
selsort xs = m : (selsort (delete m xs))
		where m = min(xs)
						
and am wondering if anyone can give tips on how this 
is done, or where I can find how this is done, in Erlang.  

Attempting to translate directly I have started with: 
						 
selsort (xs) -> [m | selsort (lists:delete m xs)] 
                ..._now what?_...;

or : 

selsort (xs) -> 
		m = lists:min(xs) in 
                [m | selsort (lists:delete m xs)]

Perhaps it is possible to:

selsort (xs) -> 
   append (lists:min(xs), selsort (lists:delete (lists:min(xs))) xs);

Or can you do something like this :
selsort(xs) ->
              [ m | m <- xs, m = lists:min(xs), delete (m xs)] 

Is there any way to refer to min(xs) as m?.



More information about the erlang-questions mailing list