سؤال

Can somebody please explain the syntax of cell data type :

datatype 'a request = READ | WRITE of 'a

datatype 'a cell = CELL of {
  reqCh : 'a request chan,
  replyCh : 'a chan
}
هل كانت مفيدة؟

المحلول

I'm not really sure what you're confused by, but this should somewhat explain the types.

The datatype 'a cell has one constructor, CELL, whose argument is a record with two fields:
reqCh, which is an 'a request chan, and replyCh, which is an 'a chan.

You don't provide the definition of chan, so I can't really clarify that. However, an 'a request has two constructors, READ and WRITE. The former has no argument, while the second takes an argument of type 'a.

For example, given some type t, a t request chan x, and an t chan y, you could have something like:

val aCell : t cell = CELL {reqCh = x, replyCh = y}
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top