I am trying to create a bounded "mailbox" like abstraction in Concurrent ML. My abstraction has 2 channels for taking values in (which are later stored in a list called "buffer") and for sending values out.
CM.make "$cml/cml.cm";
open CML;
fun mailbox inCh outCh buffer = let val inCh:int inCh =channel()
val outCh:int outCh=channel()
val buffer= [];
in
buffer= (recv inCh);
fun loop x = choose[wrap (recvEvt inCh, loop ), wrap (sendEvt (outCh, (hd buffer)), buffer=tl(), loop x)];
end
fun main()=let
val iC:int iC=channel()
val oC:int iC=channel()
val buf=[];
in
spawn(fn()=> mailbox iC oC buf);
RunCML.doit(main,NONE);
()
end
This code seems correct to be syntactically but is giving a compilation error stating
mailboxtemp.sml:7.28 Error: syntax error: inserting LET
mailboxtemp.sml:9.9 Error: syntax error: inserting IN ID END
uncaught exception Compile [Compile: "syntax error"]
raised at: ../compiler/Parse/main/smlfile.sml:15.24-15.46
../compiler/TopLevel/interact/evalloop.sml:44.55
../compiler/TopLevel/interact/evalloop.sml:296.17-296.20
Can someone please help me in finding out where I might have made a mistake?
Thanks.