News for hackers. Stuff that matters.
Re:Is your programming language unreasonable? (2015) by masklinn on Saturday October 10, 2020 @02:51PM (#24740999)
> Do most (or any) languages in which people take this approach actually enforce handling of all cases?

In "most functional languages", your result would be a sum type which requires dispatching explicitly between one case or the other, aka you wouldn't have a pair of conditionals instead you'd have something along the lines

    switch (customerOrError) {
        case IsCustomer(customer):
            Console.WriteLine(customer.ID);
        case IsError(errorMessage):
            Console.WriteLine(errorMessage);
    }
so from `customerOrError` you wouldn't have any sort of direct access to the customer or error, you must go through a dispatching construct.

In OO languages lacking sum types this sort of constructs would generally be implemented through lambdas or some sort of visitor e.g.

    customerOrError.then(
        customer => { Console.WriteLine(customer.Id); },
        onError: errorMessage => { Console.WriteLine(errorMessage) }
    );

There are no comments on this comment yet.