문제

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