comp.lang.ada
 help / color / mirror / Atom feed
From: "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
Subject: Re: Ada Interfaces and the Liskov Substitution Principle
Date: Thu, 24 May 2007 17:46:12 +0200
Date: 2007-05-24T17:44:06+02:00	[thread overview]
Message-ID: <13awcn6a95rfy.18pymw4v67avu$.dlg@40tude.net> (raw)
In-Reply-To: Pine.LNX.4.64.0705241620060.1471@th.informatik.uni-mannheim.de

On Thu, 24 May 2007 16:41:45 +0200, Stefan Lucks wrote:

> On Thu, 24 May 2007, Dmitry A. Kazakov wrote:
> 
>> On Thu, 24 May 2007 13:12:56 +0200, Stefan Lucks wrote:
> 
>>> You are using a very broad and generalised interpretation of the LSP. My
>>> interpretation -- and I believe this is the common and usual one -- is
>>> that "X: in T" in the parameterlist of a subprogram does not deal with
>>> some "artificial" type "in T", just with "T".
>>
>> If it dealt with T, then the following program were legal:
>>
>>   procedure Foo (X : in out T);
>>
>>   procedure Bar (X : in T) is
>>   begin
>>      Foo (X):  -- Fortunately illegal in Ada
>>   end Bar;
> 
> The "X: in T" part in Bar's contract means "I (Bar) will abstain from 
> using certain properties X might have" (where "certain properties" are 
> well defined, but I am too lazy to describe them explicitely).
> 
> When calling "Foo(X)", Bar is trying to break this contract -- and 
> fortunately, the compiler stops that attemtped fraud.
> 
> Note that ther is a difference between "I will abstain from using" and "I 
> don't provide",

A contract is imposed on both sides. It would be ridiculous to abstain from
anything without another party being informed, to get something in return.

> and the LSP is all about the second. The fact that inside 
> Bar, the programmer is forced to obey the promise made in the parameter 
> list is not in violation of the LSP.

It makes no sense to consider type contracts which are a subject of LSP and
ones that don't. What is the type of an in T parameter? It leaks, you
couldn't save it.

>> Yes, but then LSP should be re-formulated appropriately. And there is
>> nothing automatically wrong in disallowing operations. I would like to see
>> it in Ada.
> 
> Is there any language that allows that? I am dreaming of something like
> 
>    type Base is new Some_Tagged_Type with ...;
>      procedure Primitive_1(...);
>      procedure Primitive_2(...);
> 
>    type Super is new Base with out Primitive_2; -- this is not Ada!

Some years ago I proposed the syntax:

   procedure Primitive_2 (...) is null;

>      -- Super "inherits" Primitive_1 from Base, but not Primitive_2.
> 
>    B: Base;
>    S: Super;
> 
>    procedure Class_Wide_Base (Object: Base'Class);
>    procedure Class_Wide_Super(Object: Super'Class);
> 
>    Class_Wide_Base(B);   -- legal, of course;
>    Class_Wide_Super(S);  -- also legal, of course;
>    Class_Wide_Super(B);  -- this should be legal!!
>    Class_Wide_Base(S);   -- this should be illegal!
> 
> This would allow to "take away" operations without actually violating LSP 
> (as I understand LSP). Perhaps the following would in also do the job (of 
> course, I could not define S of type Super, but well ...):
> 
>    type Super is interface Base with out Primitive_2;

Yep, looks like supertyping.

Apart from disallowing operations one also need an ability to drop the
implementation (representation). So that you could make Super having
members you wished, or none. The latter is stripping interfaces from
concrete types. Also if the language allowed abstract record members, then
that again would become just disallowing:

   type X is record
      I : Integer;
      ...
   end record;

   type Y is new X with ...;
   function Y.I return Integer is null;
   procedure Y.I (I : Integer) is null; -- Down with it!

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de



  reply	other threads:[~2007-05-24 15:46 UTC|newest]

Thread overview: 81+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-05-23 19:47 Ada Interfaces and the Liskov Substitution Principle Stefan Lucks
2007-05-23 20:32 ` Ludovic Brenta
2007-05-23 22:00   ` Randy Brukardt
2007-05-24  0:56     ` Anh Vo
2007-05-24 18:27     ` Pascal Obry
2007-05-24 18:39       ` Dmitry A. Kazakov
2007-05-24 18:51         ` Pascal Obry
2007-05-24 22:44         ` Randy Brukardt
2007-05-24  6:57   ` Stefan Lucks
2007-05-23 20:54 ` Maciej Sobczak
2007-05-23 21:58   ` Randy Brukardt
2007-05-24  7:29     ` Maciej Sobczak
2007-05-24  8:02       ` Dmitry A. Kazakov
2007-05-24 12:58         ` Maciej Sobczak
2007-05-24 13:42           ` Dmitry A. Kazakov
2007-05-24 22:08           ` Robert A Duff
2007-07-01  1:00             ` David Thompson
2007-05-24 22:58           ` Randy Brukardt
2007-05-25  7:52             ` Maciej Sobczak
2007-05-25  8:21               ` Dmitry A. Kazakov
2007-05-25 20:27                 ` Maciej Sobczak
2007-05-26  7:48                   ` Dmitry A. Kazakov
2007-05-27  8:30                     ` Maciej Sobczak
2007-05-27 10:04                       ` Dmitry A. Kazakov
2007-05-29  8:03                         ` Maciej Sobczak
2007-05-29 13:18                           ` Dmitry A. Kazakov
2007-05-29 13:32                             ` Dmitry A. Kazakov
2007-05-29 15:34                             ` Maciej Sobczak
2007-05-29 17:07                               ` Dmitry A. Kazakov
2007-05-30  7:40                                 ` Maciej Sobczak
2007-05-30  8:43                                   ` Dmitry A. Kazakov
2007-05-30 12:54                                     ` Maciej Sobczak
2007-05-30 13:56                                       ` Dmitry A. Kazakov
2007-05-30 16:49                                         ` vgodunko
2007-05-30 20:52                                         ` Maciej Sobczak
2007-05-31  8:15                                           ` Dmitry A. Kazakov
2007-05-31 13:46                                             ` Maciej Sobczak
2007-06-01  7:29                                               ` Dmitry A. Kazakov
2007-06-01 13:32                                                 ` Maciej Sobczak
2007-06-01 14:53                                                   ` Dmitry A. Kazakov
2007-06-01 20:31                                                     ` Maciej Sobczak
2007-06-02  8:19                                                       ` Dmitry A. Kazakov
2007-06-02 16:49                                                         ` Maciej Sobczak
2007-06-03  7:09                                                           ` Dmitry A. Kazakov
2007-06-03 22:04                                                             ` Maciej Sobczak
2007-06-04  8:08                                                               ` Dmitry A. Kazakov
2007-06-04 17:02                                                                 ` Maciej Sobczak
2007-06-05  8:35                                                                   ` Dmitry A. Kazakov
2007-06-05 22:12                                                                     ` Maciej Sobczak
2007-06-06  8:21                                                                       ` Dmitry A. Kazakov
2007-06-06 14:46                                                                         ` Maciej Sobczak
2007-06-06 15:11                                                                           ` Maciej Sobczak
2007-06-06 15:32                                                                       ` Markus E Leypold
2007-05-24 10:42       ` Georg Bauhaus
2007-05-24 13:41         ` Dmitry A. Kazakov
2007-05-25 16:59         ` Markus E Leypold
2007-05-28  9:52           ` Georg Bauhaus
2007-05-28 11:50             ` Dmitry A. Kazakov
2007-05-28 23:32               ` Georg Bauhaus
2007-05-29 12:05                 ` Dmitry A. Kazakov
2007-05-29 13:33                 ` Georg Bauhaus
2007-05-29 17:29                   ` Dmitry A. Kazakov
2007-05-29 20:46                     ` Georg Bauhaus
2007-05-30  7:53                       ` Dmitry A. Kazakov
2007-05-30 13:18                       ` Georg Bauhaus
2007-05-31 10:27                         ` Dmitry A. Kazakov
2007-05-31 11:44                         ` Georg Bauhaus
2007-06-01  7:37                           ` Dmitry A. Kazakov
2007-06-01 10:07                             ` Markus E Leypold
2007-06-01 11:41                             ` Georg Bauhaus
2007-06-01 13:07                               ` Dmitry A. Kazakov
2007-05-28 13:47             ` Markus E Leypold
2007-05-28 23:12               ` Georg Bauhaus
2007-05-28 13:56             ` Markus E Leypold
2007-05-28 23:00               ` Georg Bauhaus
2007-05-24  7:39 ` Dmitry A. Kazakov
2007-05-24 11:12   ` Stefan Lucks
2007-05-24 13:56     ` Dmitry A. Kazakov
2007-05-24 14:41       ` Stefan Lucks
2007-05-24 15:46         ` Dmitry A. Kazakov [this message]
2007-05-24 15:00       ` Georg Bauhaus
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox