Code · 1 file
Sample Erlang File
Erlang is the language of telecom switches and WhatsApp, built for concurrency and fault tolerance. The Erlang sample is a small program — a customer record, a VIP check and a formatted total — that is the same in every language we offer, so you can compare them side by side.
Erlang · 719 B
Sample Erlang file
An idiomatic Erlang example: a customer record type, a VIP check, a total and a formatted loop — the same program in every language we offer.
CC0 · free for any use · Verified by an independent tool · Report a problem
%% Sample Erlang module — samplefiles.com
-module(sample).
-export([main/0, is_vip/1, total_balance/1]).
-record(customer, {id, name, balance}).
is_vip(#customer{balance = B}) -> B >= 10000.
total_balance(Customers) -> lists:sum([C#customer.balance || C <- Customers]).
main() ->
Customers = [#customer{id = 1, name = "Ada", balance = 12500.0},
#customer{id = 2, name = "Grace", balance = 830.5},
#customer{id = 3, name = "Linus", balance = 10000.0}],
[io:format("~-6s ~10.2f ~s~n", [C#customer.name, C#customer.balance, vip(C)]) || C <- Customers],
io:format("Total: ~.2f~n", [total_balance(Customers)]).
vip(C) -> case is_vip(C) of true -> "VIP"; false -> "" end.File details
Download from the command line
curl -L -o sample.erl https://files.samplefiles.com/code/erl/sample.erlwget https://files.samplefiles.com/code/erl/sample.erlhttps://files.samplefiles.com/code/erl/sample.erlprintf '%s %s\n' ba513b51a070aff46f08414299a43f796a203234ce3679d7ed2b617d185295a0 sample.erl | shasum -a 256 -cOr check the download in your browser with the checksum calculator.