Casting addresses of other Actors considered harmful

For an Actor to cast an address of another Actor is a dubious operation. Instead, an Actor should only cast its own address to interfaces that it implements. For example,

Consider the following definition:

Interface Account with getBalance[ ] ↦ Currency,
                       deposit[Currency] ↦ Void,
                       withdraw[Currency] ↦ Void

The following is an implementation of Account:

Actor SimpleAccount[aBalance:Currency]
     myBalance ≔ aBalance。
     implements Account using  
        getBalance[ ] → myBalance
        deposit[anAmount] → Void afterward  myBalance ≔ myBalance+anAmount   
        withdraw[anAmount] → (anAmount > myBalance) �
                               TrueThrow Overdrawn[ ]
                               FalseVoid afterward myBalance ≔ myBalance–anAmount

 
The above implementation of Account can be extended as follows to provide the ability to revoke some abilities to change an account by providing AccountSupervisor and AccountRevoker interfaces:

The implementation AccountSupervisor below implements the Account interface as well as AccountSupervisor and AccountRevoker interfaces as an extension of the implementation SimpleAccount: 

  Actor AccountSupervisor[initialBalance:Currency] extends SimpleAccount[initialBalance]
  withdrawableIsRevoked ≔ False,
  depositabeIsRevoked ≔ False。
  implements AccountSupervisor using  
     getRevoker[ ]→ ⍠AccountRevoker
     getAccount[ ] → ⍠Account
     withdrawFee[anAmount] → Void afterward myBalance ≔ myBalance–anAmount //  withdraw fee even if balance goes negative
  also partially reimplements exportable Account using
    withdraw[anAmount] → withdrawableIsRevoked �
                           TrueThrow  Revoked[ ]
                           False ⦂ ⍠SimpleAccount.withdraw[anAmount] 
    deposit[anAmount] → depositableIsRevoked �
                           True ⦂ Throw  Revoked[ ]
                           False ⦂ ⍠SimpleAccount.deposit[anAmount] 
   also implements exportable AccountRevoker using
      revokeDepositable[ ] →  Void afterward depositableIsRevoked ≔ True   
      revokeWithdrawable[ ] → Void afterward withdrawableIsRevoked ≔ True

 
For example, the following expression returns negative €3:
   Let  anAccountSupervisor ← AccountSupervisor.[€3]。
      Let   anAccount ← anAccountSupervisor.getAccount[ ],
            aRevoker ← anAccountSupervisor.getRevoker[ ]。
         anAccount.withdraw[€2]                           //  the balance is €1
         aRevoker.revokeWithdrawable[ ]
                                                                  //  withdrawableIsRevoked in is True        
         Try anAccount.withdraw[€5]                  //  try another withdraw
                 catch�  _  ⦂ Void                    //  ignore the thrown exception
               //  the balance remains €1
         anAccountSupervisor.withdrawFee[€4]
                           //  €4 is withdrawn even though  withdrawableIsRevoked
         anAccount.getBalance[ ]  //  the balance is negative €3


Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

Front page?


Front Page versus New Topic?

What is the difference between a Front Page and a New Topic?

Not much

To me the only difference is that front page articles appear momentarily as I navigate from lambda-the-ultimate.org to Recent Posts. Some people apparently only read the front page.

But I was being sarcastic. I don't think this post belongs on the site at all. It's in violation of the posting guidelines and I can't imagine anyone being interested. Particularly since I'm pretty sure you've posted some variant of this code before.

LtU should not be narrow minded about PL issues

Matt,

IMO, LtU should not be narrow minded about programming language issues.

The misuse of casting is a legitimate programming issue hat has not been properly addressed.

So you are against addressing the issue?

Regards,
Carl

PS. I looked for but could not find the current posting guidelines.
Is there a policy on using sarcasm to discourage discussing a programming language issue?

I suggest following the

I suggest following the links from the FAQ , linked from the navigation bar at the left.

LtU policies

You can find the policies here .

I don't think there is a policy against sarcasm, as such, except for the call for civility. It probably would have been more civil of me to overtly remind of you the policies and ask you to please pay attention to the heat/light ratio that arises in response to your posts and adjust your posting style accordingly.

I think casting can be an interesting question, but I'm probably not interested in this context.

Suggest putting in "Purpose and Policies" in LtU navigate bar

I suggest putting in "Purpose and Policies" in LtU navigate bar to make it easier to find.

Alternate interfaces of an Actor are sometimes called "facets"

Alternate interfaces of an Actor are sometimes called "facets" in the literature, cf. [Crahen 2002, Amborn 2004, Miller, et. al. 2011].

Unfortunately, current widely-used programming languages lack secure multiple interfaces for an Actor.

Articles on Facets

Here are some articles on facets:

* Eric Crahen. Facet: A pattern for dynamic interfaces. CSE Dept. SUNY at Buffalo. July 22, 2002.
* Mikael Amborn. Facet-Oriented Program Design. LiTH-IDA-EX–04/047–SE Linkőpings Universitet. 2004
* Mark S. Miller et. al. Bringing Object-orientation to Security Programming. YouTube. November 3, 2011.