Functional Error Handling v1.0.0: Result<T,E>, Option<T>, and Either<L,R>, Try_To_Result

I’m happy to announce my latest open-source Ada 2022 project: “Functional v1.0.0”!

Github: Functional Project

Alire: Functional Crate

Features:

:white_check_mark: Result<T,E> - Type-safe error handling (17 operations)

:white_check_mark: Option - Optional values (11 operations)

:white_check_mark: Either<L,R> - Disjoint union type (8 operations)

:white_check_mark: Try.To_Result - Convert exceptions to Result

:white_check_mark: Try.To_Option - Convert exceptions to Option

:white_check_mark: Pure packages - No side effects, compile-time guarantees

:white_check_mark: Zero dependencies - Just Ada 2022 standard library

:white_check_mark: Production-ready - Comprehensive compiler checks and style enforcement

6 Likes

Hi Michael!

Welcome to the forums and thank you for this contribution! This is quite a way to show and present oneself ^^

I have a small question… How does the assembly/performance look like when compared to non-typed (Result, Option, etc) types? I assume that if the library is nicely written, these types and their functions most likely just require a tiny bit of extra memory and maybe a couple more ifs?

Also, I assume this does not rely on any runtime and could therefore potentially be used in embedded systems?

Best regards,
Fer

I found this one disappointing.
For what you have (a generic, with a non-discriminated private type parameter), it would have been easier to use unconstrained arrays:

Type Index    is Boolean True..True;
Type Optional is Array (Index range <>) of Element;

None : Constant Optional( True..False ) := (Others => <>);
Function "+"( Object : Element ) return Optional is
  ( Optional'(True => Object)  );

Also, with this form you can use:

Procedure Do_Something( Parameter : Optional ) is
Begin
  --…
  For X of Parameter loop
    --Stuff operating on the element, if any, here.
  End loop;
End;

Thanks for the great contribution! I think it all looks really interesting, so thanks for putting in the effort to make this.

1 Like