home bbs files messages ]

Forums before death by AOL, social media and spammers... "We can't have nice things"

   comp.ai.fuzzy      Fuzzy logic... all warm and fuzzy-like      1,275 messages   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]

   Message 679 of 1,275   
   Dmitry A. Kazakov to All   
   Re: Fuzzy Union in C++   
   02 Feb 07 22:59:22   
   
   From: mailbox@dmitry-kazakov.de   
      
   On Fri, 02 Feb 2007 17:10:31 +0100, Seweryn Habdank-Wojewódzki wrote:   
      
   > Dmitry A. Kazakov wrote:   
   >   
   >>>>> Static error checking. Many many error you can check in compilation   
   >>>>> time. The first kind it is compatibility of the types.   
   >>>>   
   >>>> C++ and Ada are statically typed languages = you CANNOT get a type error   
   >>>> at run time unless you circumvent the type system.   
   >>>   
   >>> E.g.?   
   >>   
   >> Example of what? Of a type error? There is no type errors.   
   >   
   > Probably exceptions can be treated as type of runtime error.   
      
   Exceptions are not errors and for all they are not type errors.   
      
   >> Is it an answer to my question? Let me repeat the question:   
   >>   
   >> What is the requirement to design function Bar as a template   
   >>   
   >>    Bar(T X);   
   >>   
   >> instead of   
   >>   
   >>    Bar (T X);   
   >   
   > Consider code below   
   >   
   >    
   > template < typename T >   
   > struct Bar   
   > {   
   >         static T const zero = T(0.0);   
   >   
   >         Bar(){//default constructor   
   >         };   
   >         Bar( T const & x ) { // copy constructor   
   >         };   
   > };   
   >    
   >   
   > If you call Bar(T X0), wwhat was called default ctor or copy-ctor?   
      
   Bar in my question was a function, not a constructor, nor a type. So you   
   didn't answer my question: why the type T already present in the signature   
   of Bar need to be passed once more as a generic parameter?   
      
   As for generic types they are needed even less. The OO idiom for a set of   
   types is not a template type (C++ calls it "template class"), but a class.   
      
   The core issue is generic programming which is a programming in terms of   
   sets of types. This does not imply that these sets of types must be   
   represented solely by a bunch of macro expansions named for respectability   
   "parametric polymorphism." Fortunately, since late 60's when preprocessing   
   was first introduced, people discovered better idioms to handle   
   polymorphism.   
      
   >>>> No you cannot, templates don't allow that. Formally you could have:   
   >>>>   
   >>>>    * : T x T -> T   
   >>>>   
   >>>> But what is needed is   
   >>>>   
   >>>>    * : T1 x T1 -> T2   
   >   
   > I do not understand the problem.   
   [...]   
      
   The problem is that the result type is a function of the types of the   
   arguments. Overloading cannot solve this. Templates cannot anything beyond   
   overloading.   
      
   >>> So? I really do not understand what you mean Ada generics are contracted?   
   >>> Show me en example. I understand what means the class is constracted, but   
   >>> what means that generics is contracted.   
   >>   
   >> generic   
   >>    type T is range <>;   
   >> procedure Foo (X : T);   
   >   
   > Look in the example above, types were contracted with contract:   
   > is_special_kind.   
      
   A contract is a clause which allows to check conformance to it *separately*   
   for both contract parties. For a generic parameter to be described by a   
   contract means that the set of valid actual parameters is   
      
   1. limited to the ones stated by the contract;   
   2. all actual parameters conform to the contract are valid.   
      
   In C++ the formal parameters of templates lack contracts and violate both   
   positions. The position 1 is violated because the template formal parameter   
   specification does not limit the allowed classes in any way. The position 2   
   is violated because there exist classes for which a template instantiation   
   with these classes as actual parameters would fail. For exactly this reason   
   separate checks of template bodies are impossible. Templates cannot be   
   compiled (they are parsed as all macros), their bodies cannot be shared.   
      
   --   
   Regards,   
   Dmitry A. Kazakov   
   http://www.dmitry-kazakov.de   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]


(c) 1994,  bbs@darkrealms.ca