From: cross@spitfire.i.gajendra.net   
      
   In article <20251119192953.00005981@yahoo.com>,   
   Michael S wrote:   
   >On Wed, 19 Nov 2025 16:12:32 -0000 (UTC)   
   >cross@spitfire.i.gajendra.net (Dan Cross) wrote:   
   >   
   >> In article <10fig54$1n41a$3@dont-email.me>,   
   >> Arne Vajh_žj wrote:   
   >> >On 11/18/2025 2:04 PM, Arne Vajh_žj wrote:   
   >> >> On 11/15/2025 9:16 PM, Dan Cross wrote:   
   >> >>>> Also note the availability of the 'Valid attribute to make sure   
   >> >>>> that what   
   >> >>>> is in the variable after the unsafe conversion is actually a   
   >> >>>> valid value.   
   >> >>>   
   >> >>> Sum types make this trivial:   
   >> >>>   
   >> >>> _ _ _ _ impl SomeType {   
   >> >>> _ _ _ _ _ _ _ _ fn try_from(i: i32) -> Option {   
   >> >>> _ _ _ _ _ _ _ _ _ _ _ _ // if valid, return `Some(whatever`),   
   >> >>> _ _ _ _ _ _ _ _ _ _ _ _ // else return `None`.   
   >> >>> _ _ _ _ _ _ _ _ }   
   >> >>> _ _ _ _ }   
   >> >> (assuming Option in Rust is what it is in other languages)   
   >> >>   
   >> >> Option and Ada Valid are somewhat different.   
   >> >>   
   >> >> Option is a way for a function/method to either return   
   >> >> a value or return the fact that there is no value.   
   >> >>   
   >> >> A much better way to do that than traditional   
   >> >> return null or -1 or whatever to indicate there   
   >> >> is no value.   
   >> >>   
   >> >> Ada valid attribute is a runtime check on the result from   
   >> >> an unsafe conversion to see if it meets the constraints   
   >> >> of the data type.   
   >> >   
   >> >Option is in fashion in recent years.   
   >>   
   >> Algebraic data types have been used in functional languages   
   >> since the 1970s, starting with the "Hope" language from   
   >> Edinburgh. ML took them from Hope and popularized them, and   
   >> they leaked into Miranda, Haskell, and OCaml from there. Now   
   >> many languages support them; even C++ (`std::optional`).   
   >>   
   >> Hope was first described in a paper in 1980, but the work of   
   >> course predated that.   
   >>   
   >> That makes them about as old as VMS, and older than Ada. In   
   >> other words, they've been "In Fashion" since the 70s,   
   >   
   >That does not follow.   
   >Something existing for a long time is not the same as being fashionable   
   >for a long time.   
      
   That's a fair point, but it's also context dependent. ADTs have   
   been fashionable for a while in some communities, though perhaps   
   not in others. It depends on what kind of work you're doing and   
   what specific technologies you work with.   
      
   >Options became fashionable relatively recently, as result of growing   
   >dissatisfaction with previous fashionable item - exceptions.   
      
   Eh, now _this_ does not follow. Options and exceptions are   
   orthogonal, and many languages that support one also support the   
   other.   
      
   >Parts of programming community that are less concerned with fashion of   
   >the day ignored both of this things. They use error codes, either in   
   >crude form (like C) or more refined (like Go).   
      
   C predates ADTs, of course, and likely wouldn't have adopted   
   them even if it didn't because of the constraints of its early   
   environment.   
      
   The situation with Go is a bit more complex, and in part comes   
   from not designing the language with support for generics from   
   the start (to really make effective use of ADTs, you pretty much   
   need parametric polymorphism over data types), and generics were   
   omitted because they weren't initially sure how to make them   
   work well with interfaces, which they were pretty bullish on.   
      
   But I would argue that the Go convention of returning a tuple   
   with an explicit `error` element and allowing a simple statement   
   to be nested beween the `if` and boolean expression, is closer   
   to a Maybe monad than C's overloading an `int`, or using one a   
   return value in combination with an out parameter or something   
   similar.   
      
    - Dna C.   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   
|