comp.lang.ada
 help / color / mirror / Atom feed
* Standard."-" provided to "with function "-" (VAL1 : in VALUE_TYPE) return VALUE_TYPE is <>;" refused:
@ 2018-04-06 17:20 Mehdi Saada
  2018-04-06 19:43 ` Simon Wright
                   ` (2 more replies)
  0 siblings, 3 replies; 11+ messages in thread
From: Mehdi Saada @ 2018-04-06 17:20 UTC (permalink / raw)


The parameter is
   with function "-" (VAL1 : in VALUE_TYPE) return VALUE_TYPE is <>;
from the (simplified) package
generic
   type VALUE_TYPE is private;
   with function "-" (VAL1 : in VALUE_TYPE) return VALUE_TYPE is <>;
package NUMERIC_SIGNATURE is end Numeric_Signature;

The instantiation is:
package P_Num is new NUMERIC_SIGNATURE (VALUE_TYPE => Float);
Package_needing_a_numeric_signature is new SPREADSHEETS.Formula_Cells (P_NUM);

why do I have:
instantiation error
 operator "-" not defined for type "VALUE_TYPE" defined at ...
gprbuild: *** compilation phase failed
And putting "-" => Standard."-" "association not allowed for overloaded formal"

... Isn't able to choose the "-" with the right parameters number ?!


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Standard."-" provided to "with function "-" (VAL1 : in VALUE_TYPE) return VALUE_TYPE is <>;" refused:
  2018-04-06 17:20 Standard."-" provided to "with function "-" (VAL1 : in VALUE_TYPE) return VALUE_TYPE is <>;" refused: Mehdi Saada
@ 2018-04-06 19:43 ` Simon Wright
  2018-04-06 20:09 ` Mehdi Saada
  2018-04-06 20:37 ` AdaMagica
  2 siblings, 0 replies; 11+ messages in thread
From: Simon Wright @ 2018-04-06 19:43 UTC (permalink / raw)


Mehdi Saada <00120260a@gmail.com> writes:

> The parameter is
>    with function "-" (VAL1 : in VALUE_TYPE) return VALUE_TYPE is <>;
> from the (simplified) package
> generic
>    type VALUE_TYPE is private;
>    with function "-" (VAL1 : in VALUE_TYPE) return VALUE_TYPE is <>;
> package NUMERIC_SIGNATURE is end Numeric_Signature;
>
> The instantiation is:
> package P_Num is new NUMERIC_SIGNATURE (VALUE_TYPE => Float);
> Package_needing_a_numeric_signature is new SPREADSHEETS.Formula_Cells (P_NUM);
>
> why do I have:
> instantiation error
>  operator "-" not defined for type "VALUE_TYPE" defined at ...

Hard to say without seeing the actual spec of
Spreadsheets.Formula_Cells. But I think you need to 'use' the formal
name of the formal generic signature package.

   generic
      type T is private;
      pragma Warnings (Off, "is not referenced"); -- ~ 15 year old GNAT bug
      with function "*" (L, R : in T) return T is <>;
   package Sig is end Sig;
   
   with Sig;
   generic
      with package Actual is new Sig (<>);
   package Ops is
      function Square (L, R : Actual.T) return Actual.T;
   end Ops;
   
   package body Ops is
      function Square (L, R : Actual.T) return Actual.T is
         use Actual;                                             -- <<<
      begin
         return L * R;
      end Square;
   end Ops;
   
   with Sig;
   with Ops;
   with Ada.Text_IO; use Ada.Text_IO;
   procedure T is
      package Ints is new Sig (Integer);
      package Ops_Int is new Ops (Ints);
      package Floats is new Sig (Float);
      package Ops_Float is new Ops (Floats);
   begin
      Put_Line (Ops_Int.Square (9, 9)'Image);
      Put_Line (Ops_Float.Square (9.0, 9.0)'Image);
   end T;


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Standard."-" provided to "with function "-" (VAL1 : in VALUE_TYPE) return VALUE_TYPE is <>;" refused:
  2018-04-06 17:20 Standard."-" provided to "with function "-" (VAL1 : in VALUE_TYPE) return VALUE_TYPE is <>;" refused: Mehdi Saada
  2018-04-06 19:43 ` Simon Wright
@ 2018-04-06 20:09 ` Mehdi Saada
  2018-04-06 21:35   ` Simon Wright
  2018-04-06 20:37 ` AdaMagica
  2 siblings, 1 reply; 11+ messages in thread
From: Mehdi Saada @ 2018-04-06 20:09 UTC (permalink / raw)


Here's a minimal, compilable ... and so on ;-)
Well, not compilable because of you know what.
All with-ed things are packages, spreadsheets.formula_cells being a generic child of non-generic spreadsheets.

generic
   type VALUE_TYPE is private;
   with function "-" (VAL1, VAL2 : in VALUE_TYPE) return VALUE_TYPE is <>;
   with function "-" (VAL1 : in VALUE_TYPE) return VALUE_TYPE is <>;
   with function "**" (VAL1 : in Value_Type; VAL2 : in VALUE_TYPE) return VALUE_TYPE is <>;
   with function Factoriel (Val : in Value_Type) return Value_Type is <>;
   with function IMAGE (VAL: in value_type) return STRING;
package NUMERIC_SIGNATURE is end Numeric_Signature;


private with Spreadsheets;
package VIEWS.SPREADSHEET_bis with Elaborate_Body
is
   type SHEET_TYPE is abstract tagged limited private;
private
   use SPREADSHEETs;
   type SHEET_TYPE is abstract new Spreadsheet_Type with null record;

end VIEWS.SPREADSHEET_bis;

private with Spreadsheets;
package VIEWS.SPREADSHEET is
   TYPE SHEET_TYPE is limited private;
private
   use SPREADSHEETs;
   type SHEET_TYPE is new Spreadsheet_Type with null record;
end VIEWS.SPREADSHEET;

with NUMERIC_SIGNATURE, Ada.Text_IO, Ada.Float_Text_IO, ADA.Integer_Text_IO, Spreadsheets.String_Cells, Spreadsheets.Formula_Cells;
use Ada.Text_IO, SPREADSHEETs.String_Cells, Ada.Float_Text_IO, Ada.Integer_Text_IO;
package body VIEWS.SPREADSHEET is
   function Factoriel (Operand : in Float) return FLOAT is separate;
   function "**" (Operand, Exponent : in Float) return Float is separate;
   package P_Num is new NUMERIC_SIGNATURE                   -- L6
(VALUE_TYPE => Float,IMAGE => FLOAT'IMAGE, "-" => Standard."-");
   package Formula_Cells_Package is new Formula_Cells (P_NUM); -- L7
   use Formula_Cells_package;               -- L8
end VIEWS.SPREADSHEET;           -- L9

Same message with this simplified version:
6:04: instantiation abandoned
7:44: named association not allowed for overloaded formal
8:56: "P_NUM" is not visible
8:56: non-visible declaration at spreadsheets-formula_cells.ads:4
8:56: instantiation abandoned
9:08: "Formula_Cells_package" is undefined

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Standard."-" provided to "with function "-" (VAL1 : in VALUE_TYPE) return VALUE_TYPE is <>;" refused:
  2018-04-06 17:20 Standard."-" provided to "with function "-" (VAL1 : in VALUE_TYPE) return VALUE_TYPE is <>;" refused: Mehdi Saada
  2018-04-06 19:43 ` Simon Wright
  2018-04-06 20:09 ` Mehdi Saada
@ 2018-04-06 20:37 ` AdaMagica
  2018-04-06 21:39   ` Simon Wright
  2 siblings, 1 reply; 11+ messages in thread
From: AdaMagica @ 2018-04-06 20:37 UTC (permalink / raw)


Am Freitag, 6. April 2018 19:20:23 UTC+2 schrieb Mehdi Saada:
> The parameter is
>    with function "-" (VAL1 : in VALUE_TYPE) return VALUE_TYPE is <>;
> from the (simplified) package
> generic
>    type VALUE_TYPE is private;
>    with function "-" (VAL1 : in VALUE_TYPE) return VALUE_TYPE is <>;
> package NUMERIC_SIGNATURE is end Numeric_Signature;
> 
> The instantiation is:
> package P_Num is new NUMERIC_SIGNATURE (VALUE_TYPE => Float);
> Package_needing_a_numeric_signature is new SPREADSHEETS.Formula_Cells (P_NUM);
> 
> why do I have:
> instantiation error
>  operator "-" not defined for type "VALUE_TYPE" defined at ...
> gprbuild: *** compilation phase failed
> And putting "-" => Standard."-" "association not allowed for overloaded formal"
> 
> ... Isn't able to choose the "-" with the right parameters number ?!

The operators for Float in Standard are intrinsic. Guess this is the reason why.

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Standard."-" provided to "with function "-" (VAL1 : in VALUE_TYPE) return VALUE_TYPE is <>;" refused:
  2018-04-06 20:09 ` Mehdi Saada
@ 2018-04-06 21:35   ` Simon Wright
  0 siblings, 0 replies; 11+ messages in thread
From: Simon Wright @ 2018-04-06 21:35 UTC (permalink / raw)


First off, you can't make function "**" separate.

Having fixed that,

   $ gnatmake views-spreadsheet.adb
   gcc -c views-spreadsheet.adb
   spread.ada:31:22: file "spreadsheets-string_cells.ads" not found
   spread.ada:32:01: file "spreadsheets-formula_cells.ads" not found
   spread.ada:22:14: file "spreadsheets.ads" not found
   spread.ada:22:14: "VIEWS.SPREADSHEET (body)" depends on "VIEWS.SPREADSHEET (spec)"
   spread.ada:22:14: "VIEWS.SPREADSHEET (spec)" depends on "SPREADSHEETS (spec)"
   spread.ada:23:14: file "views.ads" not found
   spread.ada:23:14: "VIEWS.SPREADSHEET (body)" depends on "VIEWS.SPREADSHEET (spec)"
   spread.ada:23:14: "VIEWS.SPREADSHEET (spec)" depends on "VIEWS (spec)"
   gnatmake: "views-spreadsheet.adb" compilation error

so may I suggest that when you post code for us to look at you make sure
that you've included enough for us to at least be able to see the problem
you're actually asking about?

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Standard."-" provided to "with function "-" (VAL1 : in VALUE_TYPE) return VALUE_TYPE is <>;" refused:
  2018-04-06 20:37 ` AdaMagica
@ 2018-04-06 21:39   ` Simon Wright
  2018-04-06 23:08     ` Mehdi Saada
  2018-04-07  0:05     ` Mehdi Saada
  0 siblings, 2 replies; 11+ messages in thread
From: Simon Wright @ 2018-04-06 21:39 UTC (permalink / raw)


AdaMagica <christ-usch.grein@t-online.de> writes:

>> And putting "-" => Standard."-" "association not allowed for
>> overloaded formal"
>> 
>> ... Isn't able to choose the "-" with the right parameters number ?!
>
> The operators for Float in Standard are intrinsic. Guess this is the
> reason why.

No, the reason was that both binary and unary minus were included
(hence, "overloaded formals").

The signature package will work just fine leaving the operators to be
defaulted via the box <>, intrinsic or no, and it's much easier to let
the compiler do the heavy lifting (also, stops you supplying "-" for "+"
by accident!)


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Standard."-" provided to "with function "-" (VAL1 : in VALUE_TYPE) return VALUE_TYPE is <>;" refused:
  2018-04-06 21:39   ` Simon Wright
@ 2018-04-06 23:08     ` Mehdi Saada
  2018-04-07  0:05     ` Mehdi Saada
  1 sibling, 0 replies; 11+ messages in thread
From: Mehdi Saada @ 2018-04-06 23:08 UTC (permalink / raw)


... I see. It was the first time I saw "overloaded formals", so I panicked, and my mind blanked ! Problem solved.
The more time passes, the more I owe you, Simon. I'll pay you and Randy at some time in the future, in one way or another, I swear.

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Standard."-" provided to "with function "-" (VAL1 : in VALUE_TYPE) return VALUE_TYPE is <>;" refused:
  2018-04-06 21:39   ` Simon Wright
  2018-04-06 23:08     ` Mehdi Saada
@ 2018-04-07  0:05     ` Mehdi Saada
  2018-04-07 10:17       ` Mehdi Saada
  1 sibling, 1 reply; 11+ messages in thread
From: Mehdi Saada @ 2018-04-07  0:05 UTC (permalink / raw)


You may be right, in fact I think you are. When checking syntax/semantic, letting minus operators to <> works. But I uncovered a bigger problem with gps' "keep going" option: circular instantiations !!
originally: neither expressions nor spreadsheets.formula_cells were generics. They both used INTEGER.
And they could call each other: Formula_cells needs expression to calculate stuff, and expressions.formula_type (or whatever) needs spreadsheets to define a new syntax type which is aware of spreadsheets coordinates.
I don't know how it was meant to be (I won't rewrite it to be non-generic), but it had to work, so I guess being generics made both two packages not only "with" each other, but INSTANCIATE each other, which is a fr*****g dead-end.
I thought using a signature package common to both would be enough... it wasn't. And you can't "limited with-' generics. Not sure it would help, for the matter.

Is there a way out ? I would never have imagined that making things generics would wreak havoc the original design... whereas THEY proposed to change "expressions" to be generic, in the first place !

I'll take some time to review if the circular instanciation really is mandatory or not, but it really seems so.


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Standard."-" provided to "with function "-" (VAL1 : in VALUE_TYPE) return VALUE_TYPE is <>;" refused:
  2018-04-07  0:05     ` Mehdi Saada
@ 2018-04-07 10:17       ` Mehdi Saada
  2018-04-07 10:43         ` Mehdi Saada
  0 siblings, 1 reply; 11+ messages in thread
From: Mehdi Saada @ 2018-04-07 10:17 UTC (permalink / raw)


You may be right, in fact I think you are. When checking syntax/semantic, letting minus operators to <> works. But I uncovered a bigger problem with gps' "keep going" option: circular instantiations...
originally: neither expressions nor spreadsheets.formula_cells were generics. They both used INTEGER.
And they could call each other: Formula_cells needs expression to calculate stuff, and expressions.formula_type (or whatever) needs spreadsheets to define a new syntax type which is aware of spreadsheets coordinates.
I don't know how it was meant to be (I won't rewrite it to be non-generic), but it had to work, so I guess being generics made both two packages not only "with" each other, but INSTANTIATE each other.
I'll have to think about the *design* a bit.


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Standard."-" provided to "with function "-" (VAL1 : in VALUE_TYPE) return VALUE_TYPE is <>;" refused:
  2018-04-07 10:17       ` Mehdi Saada
@ 2018-04-07 10:43         ` Mehdi Saada
  2018-04-07 13:37           ` Mehdi Saada
  0 siblings, 1 reply; 11+ messages in thread
From: Mehdi Saada @ 2018-04-07 10:43 UTC (permalink / raw)


I purged my own hysterical rant.
To sum it up: the root problem is circular instantiation.
GP1 is generic, wants numerical type and operations.
GP1.G_Child needs P2, P2.Child and P2.G_Child, and P2.G_Child needs as package parameter GP1. I say needs as in "functionnaly", so instead of requiring a package generic parameter, I could stick with having the numerical signature outside, instantiate it, and instantiate GP1 with it.
But I'm not sure this is a way out.
Originally, none of these were generics, so these problems weren't happening, I think.


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Standard."-" provided to "with function "-" (VAL1 : in VALUE_TYPE) return VALUE_TYPE is <>;" refused:
  2018-04-07 10:43         ` Mehdi Saada
@ 2018-04-07 13:37           ` Mehdi Saada
  0 siblings, 0 replies; 11+ messages in thread
From: Mehdi Saada @ 2018-04-07 13:37 UTC (permalink / raw)


The most logical I could come with is:
"g_expressions"(the calculator) is a tool, hence it should be instantiated by spreadsheet.g_Formula_cells, which is the main program/library.
The spreadsheet is the main library so its generic Spreadsheet.g_formula_ cells shall be provided a g_numeric_signature, which it will use to instantiate g_expressions.
The problem, is that the son of g_expressions, call it B, depends on "spreadsheets" to define a new syntax including spreadsheet coordinates.
And like I said I can "limited with" nothing, since all packages are generics.

I hope the explanation was clear. What would you come up with ?

^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2018-04-07 13:37 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-04-06 17:20 Standard."-" provided to "with function "-" (VAL1 : in VALUE_TYPE) return VALUE_TYPE is <>;" refused: Mehdi Saada
2018-04-06 19:43 ` Simon Wright
2018-04-06 20:09 ` Mehdi Saada
2018-04-06 21:35   ` Simon Wright
2018-04-06 20:37 ` AdaMagica
2018-04-06 21:39   ` Simon Wright
2018-04-06 23:08     ` Mehdi Saada
2018-04-07  0:05     ` Mehdi Saada
2018-04-07 10:17       ` Mehdi Saada
2018-04-07 10:43         ` Mehdi Saada
2018-04-07 13:37           ` Mehdi Saada

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