
Safe-money: Money in the type system where it belongs (2017) - z1mm32m4n
https://ren.zone/articles/safe-money
======
lucas_membrane
> Rational numbers always give precise results, they don't introduce rounding
> errors and they don't require us to acknowledge a “smallest representable
> unit”

This is assertion may be invalid when the problem domain includes either (a)
compound interest calculations that require calculating a rational number
raised to a rational power, (b) expected value calculations with random
variables drawn from a probability distribution such as the normal or
exponential that is defined using transcendental functions, (c) any formula
involving e, pi or the mathematician's favorite, those three little dots ...

For example, the asserted feature of rational arithmetic does nothing for one
facing the 6th grade arithmetic problem that introduced us all to the
shortcomings of decimal numbers when I went to school: One quart of paint
covers 5 square feet; paint costs $2.75 per gallon; how much will it cost to
paint a circle 4 yards in diameter?

------
ucaetano
> Interestingly, the value of most currencies is measured in terms of the
> value of other currencies, most of which have no value other than the trust
> recursively vested in them by civilization.

This doesn't make any sense. The value of any currency is measured constantly
by its users conducting trades: when you buy a coffee, you're measuring the
value of the currency used; when you pay for a haircut, you're measuring the
value of the currency used. That is far more frequent and larger than FX
trading.

~~~
idbehold
What is the value of a coffee or haircut? How many coffees is a haircut worth?

~~~
ucaetano
Value is always personal, relative and variable. The value of things can be
expressed in terms of any other thing.

Right now, in your situation, would you rather have a coffee or a haircut?

Would you rather have 2 coffees or 1 haircut?

And so on. There are plenty of exercises to determine how you (personally)
value things, and also the shape of your utility curve. That was one of the
most interesting classes I ever took: decision and utility theories.

A lot of the work was understanding the impact of different personal (or
institutional) utility curves, how to determine your own and how to maximise
you return not in absolute terms, but in relative terms using your utility
curve.

When you take in account non-linearity of utility curves, lotteries make
sense, for example, since for most people the utility of $1 is far less than 1
millionth of the utility of a million dollars.

The same with insurance. Insurance always has a negative expected value in
absolute terms, but when you take in account that U(-$1) << U(-$1M)/1M, they
make sense, since your utility-adjusted expected return is positive. That's
also why your insurance should always have the maximum possible deductible.

Insurance works because companies and people have different utility curves.

~~~
PaulStatezny
> When you take in account non-linearity of utility curves, lotteries make
> sense, for example, since for most people the utility of $1 is far less than
> 1 millionth of the utility of a million dollars.

Can you expand on that? My intuition is telling me that $1 has exactly 1
millionth the utility of a million dollars. I must not understand.

~~~
ucaetano
While rationally you might think so, in practice you tend to act differently
than that. Here's the best example:

Let's say that you a running a risk of, for whatever reason, having to pay $1M
in any given year with a 1 in 1M probability.

Your expected outcome is -$1 per year, which isn't much. So if someone came
and offered for you to pay $1 for year for that risk to go away, you'd be
indifferent.

But utility isn't linear. Losing $1 wouldn't make a difference in your life,
but having to pay $1M would most likely destroy your life financially, leading
to significant hardship.

So the cost, to you, of -$1 isn't the same as [1/1M]*-$1M, the latter is much
higher. With that in mind, if someone offered you to pay $1 to get rid of the
risk, you'd most likely accept.

In a similar way, let's look at the positive side.

Let's say you're broke, you have $0, and I offer you $10 for 1h of your time.
Would you accept? Most likely, yes.

Now imagine you had $1M in the bank. Would you still accept $10 for 1h of your
time? Probably not. And if you had $10M in the bank, the odds of you accepting
would be even smaller.

That's because marginal utility (of pretty much anything) has diminishing
returns. The value of a thing to you is different if you have zero of it, or
if you have plenty of it.

The result is that even if you think that rationally the value is all the
same, it isn't, and you'll actually be valuing things differently. And there's
nothing irrational in that.

------
kstenerud
Or, just use IEEE 754 decimal types? That's what they were built for.

~~~
FreeFull
Those still have limited precision, and the precision varies depending on how
big the number is, which isn't suitable for money

~~~
nokcha
IEEE 128-bit decimal can handle a precision of 34 significant figures (decimal
digits). You can store a million times the world GDP (1e6 * US$75.59 trillion)
accurate to picodollars. How much more precision do you need?

~~~
smitherfield
And before someone says "hyperinflation," you could also store world GDP in
nano-Zimbabwean dollars (with 1 USD = 6.69e11 ZWL).

------
smitherfield
Rational arithmetic is not a good choice for money, since applications that
deal with money probably involve user input and so can be trivially DOS-ed.
Money should use decimal arithmetic, like COBOL. If it's good enough for
banks, it's good enough for you.

~~~
kristianp
How can rationals be DOSd? Sounds interesting.

~~~
smitherfield
By causing them to have very large terms (numerators and denominators).

------
neilwilson
The value of a currency is the effort required to obtain it.

And transitively that boils down to time - expenditure of the finite lifespan
of humans.

It's a proof of burn system.

~~~
mrleiter
Inheritance is worthless, then. As an heir I can more or less inherit from day
0 (in some jurisdictions even before) of my living life. This means there is
the possibility of me putting in zero effort, besides from being born alive,
to obtain it. Yet it obviously has some worth.

~~~
RandComment
> Inheritance is worthless, then.

That's a spurious deduction. Inheritance is a mechanism of passing value
store. Purely living off inheritance, reduces the stored value. This is a
demonstration of the concept, not a violation.

~~~
abiox
1) "The value of a currency is the effort required to obtain it"

2) (Inheritance requires no or marginal effort in acquisition)

c) "Inheritance is worthless, then."

~~~
RandComment
Currency value isn't dependent on a single entity's experience or the starving
man would set food prices. SMH

~~~
abiox
presumably your issue was with the first premise and not the conclusion.

~~~
RandComment
That is not presumed. Reappropriating how value and effort are measured is
just raising strawmen, as I intimated.

~~~
abiox
then your post was purely non-sequitur, as the syllogism's conclusion holds.
there was no strawman.

~~~
RandComment
> purely non-sequitur

That's projection. No definition was offered and the existing was discounted.
Still a strawman. Good luck with whatever.

~~~
abiox
definition provided by OP, qed:

> The value of a currency is the effort required to obtain it.

------
gcanti
Here's a (partial) porting to TypeScript [https://github.com/gcanti/money-
ts](https://github.com/gcanti/money-ts)

------
CharlesMerriam2
This is one of those articles interesting to new programmers. The actual
answer is that currency is complicated; any small library you will write it
likely to forget some complication; and, absent new open source you should go
commercial. For example, glance over the list of classes in the "money.h++"
which was sold decades ago ([http://docs.roguewave.com/legacy-
hpp/mnyug/2-9.html](http://docs.roguewave.com/legacy-hpp/mnyug/2-9.html))

TL;DR: The article is Too Long; Don't Read.

------
notavalleyman
> Money, in other words, mostly measures trust. This is less obvious for
> precious metals or cryptocurrencies because they have an intrinsic value of
> their own as well

Cryptocurrencies have intrinsic value? Did the author intent to write that or
was it an accident? S/he has grouped precious metals, which have purposes from
engineering to jewellery - with solutions to arbitrary cryptographic problems,
which are useless for everything except swindling.

~~~
ramses0
Gold is practically useless day-to-day for a lay-person except as decoration,
but represents the literal blood, sweat, tears, and toil of someone taking it
out of rocks, refining it and putting it into your hands. Also it has some
commercial use.

Cryptocurrencies likely follow a similar model. Useless to the lay-person
except as decoration. Representing a "colossal waste of resources", but having
access to the refining tools / techniques also has some commercial value.

Is gold useless except for swindling? Was trading land for gold (or vice
versa- gold for land?) was that swindling?

I'd love to hear your rebuttal.

~~~
mikro2nd
Just to put that "colossal waste of resources" in perspective... allegedly
we're wasting 60 TWh/year 'mining' Bitcoin, and this is considered (maybe
rightly) an environmental catastrophe.

We also use around (again allegedly) 220 TWh/year mining Gold.

~~~
hudon
I don't want to start a "Bitcoin is useless" flameware but to your question:
the reason why the energy consumption of proof-of-work is important is because
society hasn't found a purpose for Bitcoin to exist yet. Therefore, the energy
consumed is considered "wasted" whereas it could have been used for something
society already deems useful, like keeping the lights on.

~~~
maxxxxx
Isn't the energy use of Bitcoin also continuously growing? The cost of
extracting gold is pretty steady.

------
codezero
I'm a bit confused as to why they don't just keep the currency values in the
smallest unit for each currency. They gave an example about un-used coins
which seemed to be their justification, but I can't figure out why adding a
"scale" is a better approach. Most of the other examples were backed up by the
type system, so I feel like I'm missing something.

