diff options
author | Trygve Laugstøl <trygvis@inamo.no> | 2024-02-23 07:08:18 +0100 |
---|---|---|
committer | Trygve Laugstøl <trygvis@inamo.no> | 2024-02-23 07:08:18 +0100 |
commit | 5a9cdd3cc89507d4d74f8bded56ce5e037b3b56e (patch) | |
tree | 982ca2e7f9ac4e8c350dfb5c4f60bcfdfff5afaf /learn-you-some-erlang/discrep4.erl | |
parent | 05ae56e5e89abf2993f84e6d52b250131f247c35 (diff) | |
download | erlang-workshop-5a9cdd3cc89507d4d74f8bded56ce5e037b3b56e.tar.gz erlang-workshop-5a9cdd3cc89507d4d74f8bded56ce5e037b3b56e.tar.bz2 erlang-workshop-5a9cdd3cc89507d4d74f8bded56ce5e037b3b56e.tar.xz erlang-workshop-5a9cdd3cc89507d4d74f8bded56ce5e037b3b56e.zip |
wip
Diffstat (limited to 'learn-you-some-erlang/discrep4.erl')
-rw-r--r-- | learn-you-some-erlang/discrep4.erl | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/learn-you-some-erlang/discrep4.erl b/learn-you-some-erlang/discrep4.erl new file mode 100644 index 0000000..949a843 --- /dev/null +++ b/learn-you-some-erlang/discrep4.erl @@ -0,0 +1,21 @@ +-module(discrep4). +-export([run/0]). +-type cents() :: integer(). +-type account() :: atom(). +-type transaction() :: {'give', cents(), account()}. + +run() -> + Tup = money(5, you), + some_op(item(count,Tup), item(account,Tup)). + +-spec money(cents(), account()) -> transaction(). +money(Num, Name) -> {give, Num, Name}. + +-spec item('count', transaction()) -> cents(); + ('account', transaction()) -> account(). +item(count, {give, X, _}) -> X; +item(account, {give, _, X}) -> X. + +some_op(A,B) -> A + B. + + |