Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I imagine an ada dev would find the pattern grating over the decades, so it reads like an expression of that experience.
 help



Yep. And sometimes it's hype over the weirdest things... a good example "dependency injection".

    Generic
      Type Index   is (<>);                                      -- Any discrete type.
      Type Element is limited private;                           -- Any non-discriminated type.
      Type Vector  is array(index range <>) of element;          -- An array-type of Element, indexed by Index.
      with Function "="(Left, Right: Element) return Boolean <>; -- Equal, defaulted.
      with Function "<"(Left, Right: Element) return Boolean <>; -- Less-than, defaulted.
    Function Generic_Sort( X : Vector ) return Vector;
Now when we instantiate we can inject '>' in place of the '<', reversing the direction of the sort:

    Function Sort is new Generic_Sort( Index => Integer, Element => Integer, Vector => Integer_Array, "<" => ">");



Consider applying for YC's Summer 2026 batch! Applications are open till May 4

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: