Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
type storage = int
module Counter = struct
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, why the module wrapper?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For consistency with the JsLIGO example? I suppose it's not necessary here except that devs probably put most contracts in a module. If you think it's distracting I'll take it out.

type storage_type = int
type return_type = operation list * storage_type
Comment on lines +2 to +3
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are we doing the type x_type thing?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I usually do that to distinguish types from values. Otherwise statements like storage: storage = ... can get confusing.


type ret = operation list * storage
(* Three entrypoints *)

(* Three entrypoints *)
[@entry]
let add (value : int) (store : storage_type) : return_type =
[], store + value

[@entry]
let increment (delta : int) (store : storage) : ret = [], store + delta
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the previous names seems better overall, increment, decrement and delta vs add, sub and value.


[@entry]
let decrement (delta : int) (store : storage) : ret = [], store - delta

[@entry]
let reset (() : unit) (_ : storage) : ret = [], 0
[@entry]
let sub (value : int) (store : storage_type) : return_type =
[], store - value

[@entry]
let reset (_p : unit) (_s : storage_type) : return_type =
[], 0
end
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
type storage = int;
type ret = [list<operation>, storage];
namespace Counter {
type storage_type = int;
type return_type = [list<operation>, storage_type];

// Three entrypoints
// Three entrypoints

// @entry
const increment = (delta: int, store: storage): ret =>
[[], store + delta];
// @entry
const add = (value: int, store: storage_type): return_type =>
[[], store + value];

// @entry
const decrement = (delta: int, store: storage): ret =>
[[], store - delta];
// @entry
const sub = (value: int, store: storage_type): return_type =>
[[], store - value];

// @entry
const reset = (_p: unit, _s: storage): ret => [[], 0]
// @entry
const reset = (_p: unit, _s: storage_type): return_type =>
[[], 0];
}