type definitions of IMAP
In naive implementation, IMAP requires same constructor names in different context. For example, RECENT is used at the SEARCH command, STATUS command, and in STATUS response. In this case, I would like to define as follows...
type Mailbox = String data IMAPCommand = STATUS Mailbox [StatusQuery] | SEARCH [SearchQuery] : data StatusQuery = RECENT | MESSAGES | : data SearchQuery = RECENT | SEEN | : data MailboxData = RECENT Integer | SEEN Integer | :
In addition to this, IMAP commands are separated as some groups. For example, UID command is used for SEARCH, FETCH, STORE, and COPY. How can I describe this relation in the type definition?
By using polymorphic variant of OCaml, these can be described easily and elegantly.
In conclusion, such relations may be described using not only type definitions, but also function definitions.