From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,FREEMAIL_FROM autolearn=unavailable autolearn_force=no version=3.4.4 X-Received: by 10.200.34.239 with SMTP id g44mr3375780qta.3.1464975118009; Fri, 03 Jun 2016 10:31:58 -0700 (PDT) X-Received: by 10.157.4.36 with SMTP id 33mr69011otc.15.1464975117971; Fri, 03 Jun 2016 10:31:57 -0700 (PDT) Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!news.eternal-september.org!mx02.eternal-september.org!feeder.eternal-september.org!usenet.blueworldhosting.com!feeder01.blueworldhosting.com!peer02.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!p34no2219732qgp.1!news-out.google.com!z5ni83qge.0!nntp.google.com!q32no3239202qgq.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Fri, 3 Jun 2016 10:31:57 -0700 (PDT) In-Reply-To: Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=75.161.97.176; posting-account=lJ3JNwoAAAAQfH3VV9vttJLkThaxtTfC NNTP-Posting-Host: 75.161.97.176 References: User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: Subject: Re: Mixing operators and dot notation From: Shark8 Injection-Date: Fri, 03 Jun 2016 17:31:58 +0000 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-Received-Bytes: 6230 X-Received-Body-CRC: 2766115915 Xref: news.eternal-september.org comp.lang.ada:30587 Date: 2016-06-03T10:31:57-07:00 List-Id: On Friday, June 3, 2016 at 5:09:23 AM UTC-6, Alejandro R. Mosteo wrote: > To give you the essence. I'm back to trying to get a minimal ReactiveX=20 > (http://reactivex.io)-like thing working. The gist is that you can chain= =20 > many transformation operations: >=20 > SourceType.Generate_Data > .Op1 (...) > ... > .OpN (...) > .Endpoint (Operate_With_Resulting_Transformed_Data); >=20 > As long as the ops receive and emit the same type, I can do it with=20 > generics. But those are in the minority. Since they receive one type and= =20 > emit another, I'm trying to find the most elegant Ada solution that=20 > keeps compile-time type checking if possible, and straight code flow=20 > (this is where parentheses in the solutions above don't work, since they= =20 > create "boxes within boxes"). I'm doing something similar with Byron. Also note that the "boxes within boxes" can be used to some advantage as yo= u can make generics dependent on generics: this requires some up-front desi= gning and discipline though... and really learning the generic system. There is one possible solution for you that doesn't quite require such gymn= astics: Package Testing_Package is =20 Type Type_Interface is Interface; Function Operation_1(Object : Type_Interface) return Type_Interface is = abstract; -- However many base operations there are. =20 Generic Type X is private; with Function Op_1( Data : X ) return X; -- with for appropriate operations. Package Make_Interfaced is =09 Type Y is new Type_Interface with record Data : X; end record; =09 Function Create( Object : X ) return Y; overriding Function Operation_1(Object : Y) return Y; =09 Function "+" (Object : X) return Y renames Create; Function "-" (Object : Y) return X; Private =09 Function Operation_1(Object : Y) return Y is ( Data =3D> Op_1(Object.Data) ); =20 Function Create( Object : X ) return Y is ( Data =3D> Object ); =09 Function "-" (Object : Y) return X is ( Object.Data ); =09 End Make_Interfaced; =20 =20 Generic Type A(<>) is new Type_Interface with private; Type B(<>) is new Type_Interface with private; With Function Operation( Item_1 : A; Item_2 : B ) return A; Function Concat( Left : A; Right : B ) return Type_Interface'Class; =20 Function Concat( Left : A; Right : B ) return Type_Interface'Class is ( Type_Interface'Class(Operation(Left,Right)) ); =20 =20 End Testing_Package; >=20 > I'm pursuing several approaches: one is to use a tagged type with all=20 > operations (which is the Java approach), and marshalling of arguments=20 > via generics (which java doesn't need by having in-place instatiations).= =20 > That's not too bad but duplicates code, in the sense that for each=20 > operation you need too pieces: the operation and the marshalling, but at= =20 > least the library user writes her code using only her own types, which I= =20 > like: >=20 > SourceType.Generate_Data > .Op1 (FromXtoY.Transformer > (User_FuncX'Access)) -- User_FuncX returns Y > .Op2 (FromYtoZ.Transformer > (User_FuncY'Access)) -- User FuncY returns Z > .Endpoint (Z_Type.As_Z (Function'Access)); >=20 > Of course with proper shorter names it looks better. However, checks are= =20 > performed at run time. >=20 > Another idea was to use "&" instead of dot notation, >=20 > Stream :=3D SourceType.Generate_Data & > Type1.Op1(...) & > Type2.Op2(...) & > Type4.Endpoint (...); >=20 > having all needed "&" in scope. This possibly requires more "use type"=20 > clauses and I haven't tested it yet but I think it should work and be=20 > neater, having a "&" taking different left and right types. >=20 > Another way I was trying was the hybrid one that doesn't work: Using dot= =20 > notation while there are no type changes, and & to cast to the new type= =20 > only when needed. (I needed it to work even without parentheses.) >=20 > The root of the problem is in that, to keep code natural (and=20 > compile-time checks) I want to keep the user unaware of class-wide=20 > wrappers, and that involves generics. Once you have generic instances,=20 > you lose dot notation for transforming operations (since you need to=20 > somehow glue two types together, and the new operations are no longer=20 > primitive). (On this path, I have an idea involving two instantiations=20 > for each type being used, but I'm trying to avoid that for now). (Also I= =20 > had a neat approach using elaboration-time instantiations but I collided= =20 > with accessibility checks since I didn't want everything to be at=20 > library level.) >=20 > Anyway, I will keep playing and probably come back for criticism/ideas.= =20 > It's possible I'm missing other options, of course, which are welcome. I= =20 > will post my experimental repository once/if something takes shape. >=20 > =C3=81lex.