-1

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.

1 Answers1

1

Your code is syntactically ill-formed and has numerous type errors in the bits that are well-formed. Here are some suggestions:

  1. Your fun loop... is a definition, but you list it in the middle of an expression. Definitions must be at the top-level or within a let block (you can move it earlier, but unless you call loop somewhere, it won't do anything.
  2. You don't need a semicolon at the end of a definition. That might even be ill-formed.
  3. The line buffer= (recv inCh); compares buffer (which you have defined to mean []) with the result of calling (recv inCh), then discards that result. Other than for the side effect of calling recv inCh, that is entirely meaningless.
  4. val inCh:int inCh =channel() is syntactically ill-formed. I assume that you mean val inCn : int = channel(), but that doesn't type, because channel() does not return an int.

Please check http://www.eecs.ucf.edu/~leavens/learning-SML.html and work through one of the SML tutorials first.

creichen
  • 1,728
  • 9
  • 16