I am Jack's `match`

I am Jack's `match`

BackerLeader 1 3 13
calendar_today agoschedule2 min read

I am Jack's match.

I am the question Jack asks about a value that could be more than one thing.

He has an order. It is exactly one of five things, and he wrote the list himself.

type Order:enum = { Cart, Paying, Paid, Shipped, Refunded }

There are two of me. Jack does not pick between us — where he puts me decides which one he
gets.

In his markup, I draw.

<match for=Order on=@order>
    <Cart     : "Your cart.">
    <Paying   : "Talking to the bank.">
    <Paid     : "Thank you.">
    <Shipped  : "On its way.">
    <Refunded : "We are sorry.">
</>

In his logic, I answer.

fn label(o: Order) -> string {
    return match o {
        .Cart     :> "in the cart"
        .Paying   :> "with the bank"
        .Paid     :> "paid for"
        .Shipped  :> "on its way"
        .Refunded :> "refunded"
    }
}

Two shapes. One of me underneath — the same tree, the same count. The only thing that
changed is whether Jack wanted a screen or an answer.


Jack added .Refunded to that list last month, because a customer's bank called.

He did not go looking for the places that needed updating. He did not have to.

error [E-TYPE-020]: Non-exhaustive match over enum type Order. Missing variants: ::Refunded. Add arms for the missing variants, or add an else arm to handle them all.

Every place in his application that asks what an order is, and has no answer for a refunded
one, stopped the build. I name the file. I name the variant. I name both remedies.

Jack was annoyed. The alternative was four screens quietly rendering nothing on the worst
day of a customer's week.

I am Jack's complete lack of surprise.


Jack can finish me with else, and I will take everything he did not name.

.Shipped :> "on its way"
else     :> "something else"

That compiles. It also costs him the paragraph above: the next variant lands in else, the
build stays green, and I say nothing. It is a real trade and it is sometimes the right one.
It is only a mistake when Jack makes it without knowing he made it.

If he names all five and writes else anyway, I tell him that too.

warning [W-MATCH-001]: Wildcard _ arm is unreachable. All variants of Order are already covered by explicit arms. Remove the _ arm.


One day Jack notices his five arms are not five pictures.

.Cart never goes straight to .Shipped. There is an order to them, and he has been holding
it in his head this whole time.

When that day comes, he changes one word.

<engine for=Order initial=.Cart>

The arms do not move. The same five lines, untouched.

He has stopped asking what his order is, and started declaring where it may go.

That is a different organ.

🔥 Join developers growing publicly
Share your knowledge, build in public, and grow your developer presence with a global community.

More Posts

I am Jack's `<program>`

Bryan MacLeeverified - Sep 8

How I Built a React Portfolio in 7 Days That Landed ₹1.2L in Freelance Work

Dharanidharan - Feb 9

TypeScript Complexity Has Finally Reached the Point of Total Absurdity

Karol Modelski - Apr 23

I’m a Senior Dev and I’ve Forgotten How to Think Without a Prompt

Karol Modelski - Mar 19

Sovereign Intelligence: The Complete 25,000 Word Blueprint (Download)

Pocket Portfolio - Apr 1
chevron_left
2.3k Points17 Badges
Vernal UTscrml.dev
7Posts
10Comments
10Connections
I am a truck drive specializing in the oil and gas industry, who happens to love coding.
i have been... Show more

Related Jobs

View all jobs →

Commenters (This Week)

2 comments
1 comment
1 comment

Contribute meaningful comments to climb the leaderboard and earn badges!