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,WEIRD_PORT autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII Path: g2news2.google.com!postnews.google.com!c29g2000yqd.googlegroups.com!not-for-mail From: Martin Newsgroups: comp.lang.ada Subject: Re: Saturation arithmetic woes. Date: Wed, 29 Jul 2009 10:13:48 -0700 (PDT) Organization: http://groups.google.com Message-ID: References: <1a16b458-0201-4320-9787-2836ed58f991@e27g2000yqm.googlegroups.com> NNTP-Posting-Host: 20.133.0.8 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Trace: posting.google.com 1248887628 2477 127.0.0.1 (29 Jul 2009 17:13:48 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Wed, 29 Jul 2009 17:13:48 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: c29g2000yqd.googlegroups.com; posting-host=20.133.0.8; posting-account=g4n69woAAACHKbpceNrvOhHWViIbdQ9G User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.9.1.1) Gecko/20090715 Firefox/3.5.1,gzip(gfe),gzip(gfe) Xref: g2news2.google.com comp.lang.ada:7416 Date: 2009-07-29T10:13:48-07:00 List-Id: On Jul 29, 6:03=A0pm, xorque wrote: > generic > =A0 type Discrete_Type is (<>); > > package Saturation is > > =A0 type Saturated_Type is new Discrete_Type; > > =A0 function "+" > =A0 =A0 (Left =A0: Saturated_Type; > =A0 =A0 =A0Right : Saturated_Type) return Saturated_Type; > > end Saturation; > > package body Saturation is > > =A0 function "+" > =A0 =A0 (Left =A0: Saturated_Type; > =A0 =A0 =A0Right : Saturated_Type) return Saturated_Type > =A0 is > =A0 =A0 Temp_Left =A0: constant Discrete_Type :=3D Discrete_Type (Left); > =A0 =A0 Temp_Right : constant Discrete_Type :=3D Discrete_Type (Right); > =A0 begin > =A0 =A0 if Temp_Left + Temp_Right > Discrete_Type'Last then > =A0 =A0 =A0 return Saturated_Type (Discrete_Type'Last); > =A0 =A0 end if; > =A0 =A0 if Temp_Left + Temp_Right < Discrete_Type'First then > =A0 =A0 =A0 return Saturated_Type (Discrete_Type'First); > =A0 =A0 end if; > > =A0 =A0 return Saturated_Type (Temp_Left + Temp_Right); > =A0 end "+"; > > end Saturation; > > with Saturation; > with Ada.Text_IO; > > procedure Main is > =A0 type T is range 1 .. 10; > > =A0 package T_Saturated is new Saturation (T); > =A0 package IO =A0 =A0 =A0 =A0 =A0renames Ada.Text_IO; > =A0 package TIO =A0 =A0 =A0 =A0 is new Ada.Text_IO.Integer_IO > (T_Saturated.Saturated_Type); > > =A0 use type T_Saturated.Saturated_Type; > > =A0 X : constant T_Saturated.Saturated_Type :=3D 5; > =A0 Y : constant T_Saturated.Saturated_Type :=3D 9; > begin > =A0 TIO.Put (X + Y); -- 10 > =A0 IO.New_Line; > end Main; > > saturation.adb:10:18: there is no applicable operator "+" for type > "Discrete_Type" defined at saturation.ads:2 > saturation.adb:13:18: there is no applicable operator "+" for type > "Discrete_Type" defined at saturation.ads:2 > saturation.adb:17:38: there is no applicable operator "+" for type > "Discrete_Type" defined at saturation.ads:2 > > I'm afraid I'm not well versed in the rules regarding operator name > resolution... generic type Discrete_Type is (<>); with function "+" (L, R : Discrete_Type) return Discrete_Type is <>; package Saturation is You need to provide a suitable "+" operator. Cheers -- Martin