Comment

Comment by zero_shift

Now that we have defined a language without booleans, we need some way to coalesce these optional values

We ideally want an infix function that can reduce the "truthiness" of two values.

Let us imagine this language is a Haskell-type-thing, and we can define pseudo-operators with pattern matching

    infixr 3 &&
    (&&) :: Optional -> Optional -> Optional
    Empty && _       = Empty
    _ && Empty       = Empty
    Some A && Some B = Some A
    _ && _           = Empty

    infixr 2 ||
    Some || _     = Some
    None || Some  = Some
    None || None  = None
    _    || _     = None 
Hmm, let's see how that looks

    a = b && c
    d = e || f
The good news is that we are free from the tyranny of booleans. The bad news is that we just reinvented JavaScript :-)
parent zero_shift 1 year ago

Discussion

Live from the official Hacker News API

A modern reader for Hacker News · SvelteKit + Skeleton