This task is to determine if there is only one instance of an application running. If the program discovers that an instance of it is already running, then it should display a message indicating that it is already running and exit.

functor
import Application Open System
define
   fun {IsAlreadyRunning}
      try
	 S = {New Open.socket init}
      in
	 {S bind(takePort:12345)}
	 false
      catch system(os(os "bind" ...) ...) then
	 true
      end
   end
 
   if {IsAlreadyRunning} then
      {System.showInfo "Exiting because already running."}
      {Application.exit 1}
   end
   {System.showInfo "Press enter to exit."}
   {{New Open.file init(name:stdin)} read(list:_ size:1)}
   {Application.exit 0}
end