[State] Read-only attributes

Vincenzo Ciancia <[email protected]>
Newsgroups gmane.comp.lang.haskell.gui
Message-ID <[email protected]>
On Sat, 5 Apr 2003 06:55:28 +0100
Glynn Clements <[email protected]> wrote:

> 
>  Read-only or write-only attributes could be implemented by throwing
>  an error for prohibited operations. Read-only attributes could be
>  implemented by simply ignoring write operations.

From now on, I propose to tag messages about state handling with the
[State] keyword, and invite people who are interested in other aspects
of the CGA to start their own discussions.

We could distinguish between two kind of read-only attributes: those
which are fixed at creation-time and those which are written somewhere
and read somewhere else. Apart from this detail, wich is perhaps
unuseful, I think that we should avoid run-time errors when we can model
them in the type system, as it leads to a more detailed machine-checked
specification. 

For the specific case, I like an approach where a state variable has two
components: a read-only one and a write-only one, as in

Variable a = Variable 
   { writeable :: Writeable a, 
     readable :: Readable a }

A read-only attribute is exposed with just the "Readable a" type, not
with the "Variable a" one.

I have to read the other e-mails, and to fit this approach in the
getter/setter one, comments are welcome.

Vincenzo
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.