Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
947744f
list functions in AS, inspired by SML Basis library
matthewhammer Feb 4, 2019
b97eb67
done with SML basis List module; starting streams (aka lazy lists)
matthewhammer Feb 4, 2019
2012f69
readme stub
matthewhammer Feb 4, 2019
35cf9aa
nits
matthewhammer Feb 4, 2019
5a470d7
a stream function: mapfilter
matthewhammer Feb 4, 2019
e3da12b
another stream function: map
matthewhammer Feb 4, 2019
6c9ad8e
stream function 'merge'
matthewhammer Feb 4, 2019
4686876
nits; typos
matthewhammer Feb 5, 2019
4d3f864
address feedback from Andreas
matthewhammer Feb 5, 2019
1a83957
fix type error, with Andreas's help
matthewhammer Feb 5, 2019
0ebde57
fix type error, with Andreas's help
matthewhammer Feb 5, 2019
6e1f251
Merge branch 'collections' of github.com:dfinity-lab/actorscript into…
matthewhammer Feb 5, 2019
2b682e3
update readme
matthewhammer Feb 5, 2019
5a9149f
starting hashtrie; many loose ends remain
matthewhammer Feb 6, 2019
c8629f5
hashtrie construction operations; everything needs testing now
matthewhammer Feb 6, 2019
d4f9e91
minor: md formatting
matthewhammer Feb 6, 2019
5c25eed
minor: typo
matthewhammer Feb 6, 2019
a978eb7
minor
matthewhammer Feb 7, 2019
06b19fe
encode functional sets as hashtries; run a baby test, encoding hashes…
matthewhammer Feb 12, 2019
95f41e4
hashtrie: debugging reveals some bugs
matthewhammer Feb 12, 2019
415d631
hashtries: simple tests on sets pass; tests insertion & membership
matthewhammer Feb 12, 2019
9236308
hashtries: finish little tests on sets; fix typo
matthewhammer Feb 12, 2019
829003a
hashtrie: more emulation of sum types (see AST-42)
matthewhammer Feb 19, 2019
5c36751
squash! hashtrie: more emulation of sum types (see AST-42)
matthewhammer Feb 19, 2019
2354ec7
simple merge on hash tries; union on sets
matthewhammer Feb 20, 2019
0ed35ee
minor: update issue link
matthewhammer Feb 20, 2019
6ff2bf8
hash tries: conj, disj; sets: intersect
matthewhammer Feb 21, 2019
a4d439a
hashtrie: debugging conj and disj; disj has bugs
matthewhammer Feb 21, 2019
30ea11b
hashtrie: debug disj; write+test setCard, setEq
matthewhammer Feb 21, 2019
5ddfcbb
hashtrie: filter
matthewhammer Feb 22, 2019
3a3524b
hashtrie: mapFilter
matthewhammer Feb 22, 2019
ebc656a
hashtrie: fold, exists, forall
matthewhammer Feb 22, 2019
12a7c2f
minor: doc disj
matthewhammer Feb 22, 2019
0479534
hashtrie: update TODOs
matthewhammer Feb 22, 2019
b88e245
Merge remote-tracking branch 'origin' into collection-modules
matthewhammer Mar 6, 2019
06700be
package list functions into a record, in lieu of modules; cleanup
matthewhammer Mar 6, 2019
3307685
Trie and Set modules; Makefile for regression tests
matthewhammer Mar 6, 2019
3ce9f33
further decomposition of modules
matthewhammer Mar 6, 2019
6bdb6d5
file rename
matthewhammer Mar 6, 2019
dabdab4
clean up
matthewhammer Mar 6, 2019
7c1fde4
fix typo
matthewhammer Mar 6, 2019
646d903
minor: remove confusing comments
matthewhammer Mar 6, 2019
fca20a9
rough draft of Produce Exchange, skeleton
matthewhammer Mar 7, 2019
52fd3a3
Makefile avoids re-running asc
matthewhammer Mar 7, 2019
97f15dd
simplify fake module construction exploiting new { <decs>} syntax
crusso Mar 7, 2019
1d4b273
indent 'module' bodies
crusso Mar 7, 2019
d0b0a8d
forgot to fix SetDb.as
crusso Mar 7, 2019
6e9f054
Makefile: module output files in a separate directory
matthewhammer Mar 7, 2019
4ec6fc4
Makefile nits; more futzing for later
matthewhammer Mar 7, 2019
8953b59
move collections in source tree
matthewhammer Mar 7, 2019
165d088
fix Makefile, post move
matthewhammer Mar 7, 2019
5274e4c
move produce exchange to 'examples' subdir
matthewhammer Mar 7, 2019
7049305
Makefile nits
matthewhammer Mar 7, 2019
f580a97
add stdlib dir to other Makefile, and nix derivation
matthewhammer Mar 7, 2019
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
6 changes: 6 additions & 0 deletions default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,11 @@ rec {
"test/.*.sh"
"samples/"
"samples/.*"
"stdlib/"
"stdlib/.*Makefile.*"
"stdlib/.*.as"
"stdlib/examples/"
"stdlib/examples/.*.as"
];

buildInputs =
Expand All @@ -112,6 +117,7 @@ rec {
buildPhase = ''
patchShebangs .
asc --version
make -C stdlib ASC=asc all
make -C samples ASC=asc all
make -C test/run VERBOSE=1 ASC=asc all
make -C test/fail VERBOSE=1 ASC=asc all
Expand Down
1 change: 1 addition & 0 deletions src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ clean:
$(MAKE) -C ../test clean

test: $(NAME)
$(MAKE) -C ../stdlib ASC=$(ASC) all
$(MAKE) -C ../test ASC=$(ASC) all
$(MAKE) -C ../samples ASC=$(ASC) all

Expand Down
1 change: 1 addition & 0 deletions stdlib/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
_out
110 changes: 110 additions & 0 deletions stdlib/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
ASC=../src/asc
OUTDIR=_out

## VT100 stuff
HRULE="\x1b[2;34m----------------------------------------------------------------\x1b[0m"
MODULE_NAME="\x1b[1;32mModule:\x1b[1;34m"
BEGIN="\x1b[0;1mBegin...\x1b[0m"
DONE="\x1b[1mDone.\n"$(HRULE)
MODULE_NAME_COLOR="\x1b[0;1;34m"
NO_COLOR="\x1b[0m"

# Add new module targets here:
MODULES=\
List \
ListTest \
Trie \
Set \
SetDb \
SetDbTest \
ProduceExchange \


OUTFILES=$(addsuffix .out, $(MODULES))

OUTPATHS=$(addprefix $(OUTDIR)/, $(OUTFILES))

.PHONY: default all clean startmsg

default: all

startmsg:
@echo Begin build: $(MODULE_NAME_COLOR)$(MODULES)$(NO_COLOR)...
@echo $(HRULE)

all: $(OUTDIR) startmsg $(OUTPATHS)
@echo Build done : $(MODULE_NAME_COLOR)$(MODULES)$(NO_COLOR)

clean:
rm -rf $(OUTDIR)

$(OUTDIR):
@mkdir $(OUTDIR)


$(OUTDIR)/List.out: $(OUTDIR) list.as
@echo $(MODULE_NAME) $(basename $(notdir $@))
@echo $(BEGIN)
$(ASC) -r $(filter-out $(OUTDIR), $^) > $@
@echo $(DONE)

$(OUTDIR)/ListTest.out: $(OUTDIR) list.as listTest.as
@echo $(MODULE_NAME) $(basename $(notdir $@))
@echo $(BEGIN)
$(ASC) -r $(filter-out $(OUTDIR), $^) > $@
@echo $(DONE)

$(OUTDIR)/Trie.out: $(OUTDIR) list.as trie.as
@echo $(MODULE_NAME) $(basename $(notdir $@))
@echo $(BEGIN)
$(ASC) -r $(filter-out $(OUTDIR), $^) > $@
@echo $(DONE)

$(OUTDIR)/Set.out: $(OUTDIR) list.as trie.as set.as
@echo $(MODULE_NAME) $(basename $(notdir $@))
@echo $(BEGIN)
$(ASC) -r $(filter-out $(OUTDIR), $^) > $@
@echo $(DONE)

$(OUTDIR)/SetDb.out: $(OUTDIR) list.as trie.as set.as setDb.as
@echo $(MODULE_NAME) $(basename $(notdir $@))
@echo $(BEGIN)
$(ASC) -r $(filter-out $(OUTDIR), $^) > $@
@echo $(DONE)

$(OUTDIR)/SetDbTest.out: $(OUTDIR) list.as trie.as set.as setDb.as setDbTest.as
@echo $(MODULE_NAME) $(basename $(notdir $@))
@echo $(BEGIN)
$(ASC) -r $(filter-out $(OUTDIR), $^) > $@
@echo $(DONE)

$(OUTDIR)/ProduceExchange.out: $(OUTDIR) list.as trie.as examples/produceExchange.as
@echo $(MODULE_NAME) $(basename $(notdir $@))
@echo $(BEGIN)
$(ASC) -r $(filter-out $(OUTDIR), $^) > $@
@echo $(DONE)


#########################################################################################
# TODO(Matthew): Figure out why this "compressed" version of the rules doesn't work.

# $(OUTDIR)/List.out: $(OUTDIR) list.as ; @$(doModule)

# $(OUTDIR)/ListTest.out: $(OUTDIR) list.as listTest.as ; @$(doModule)

# $(OUTDIR)/Trie.out: $(OUTDIR) list.as trie.as ; @$(doModule)

# $(OUTDIR)/Set.out: $(OUTDIR) list.as trie.as set.as ; @$(doModule)

# $(OUTDIR)/SetDb.out: $(OUTDIR) list.as trie.as set.as setDb.as ; @$(doModule)

# $(OUTDIR)/SetDbTest.out: $(OUTDIR) list.as trie.as set.as setDb.as setDbTest.as ; @$(doModule)

# $(OUTDIR)/ProduceExchange.out: $(OUTDIR) list.as trie.as produceExchange.as ; @$(doModule)

# define doModule =
# @echo $(MODULE_NAME) $(basename $(notdir $@))
# @echo $(BEGIN)
# $(ASC) -r $(filter-out $(OUTDIR), $^) > $@
# @echo $(DONE)
# endef
20 changes: 20 additions & 0 deletions stdlib/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
[See #127](https://github.com/dfinity-lab/actorscript/issues/127)

Critical modules
==================
- [x] **List**: See [`List` module from SML Basis library](http://sml-family.org/Basis/list.html).
- [x] **Hashtrie**: Persistent maps, as functional hash tries.
- [x] **Set**: Persistent sets, based directly on persistent maps.
- [ ] **Hashtable**: Mutable maps, as imperative hash tables.

Secondary modules
==================
These modules _may_ be useful in the collections library:
- [ ] **Stream**: Type def done; most operations are pending...

Other modules
==================
These modules are merely exercises (toys/examples), and _not_ essential to the collections library:
- [ ] **Thunk**: Type def and some operations are done.


214 changes: 214 additions & 0 deletions stdlib/examples/produceExchange.as
Original file line number Diff line number Diff line change
@@ -0,0 +1,214 @@
// Produce Exchange Dapp
// =====================
//
// Start here:
// - Detailed examples: https://dfinity.atlassian.net/wiki/x/joXUBg
// - More background: https://dfinity.atlassian.net/wiki/x/4gg5Bg
//

// Open Questions:
// -------------------------------------------------

// 1. Massive result messages:
// How do we represent and send these?
//
// - lazy lists? (seems "easy" from AS programmer perspective, but
// requires non-first-order data in the IDL)
//
// - list iterators? (almost as good as lazy lists, but requires
// references in the IDL, and complicates the GC story).
//
// - arrays? (expensive to build and send; can become way *too big*).
//

// 2. For now, wan we assume that the canister is maintained by the
// central authority?

////////////////////////////////////////////////////////////////

// Use the standard library of AS:
// ===============================
//

// Collections implement internal tables:
// --------------------------------------
// import Table (same as Trie?) xxx

// import Date
// xxx Dates, eventually from a standard library:
type Date = Nat;

// xxx standard weight units?
type Weight = Nat;

// xxx standard price units?
type Price = Nat;

/////////////////////////////////////////////////////////////////

// Fixed types
// ===============================
//
// We assume some fixed types (for now).
// Updating these types requires a canister upgrade.
//
// ?? defined by the central authority, aka, the "canister maintainer"?
//

type Unit = Nat; // xxx replace with a variant type
type Grade = Nat; // xxx replace with a variant type

type TruckType = Nat; // ??? replace with a variant type

type TruckCapacity = Weight;

type Quantity = Nat;

type PricePerUnit = Price; // needed to calculate prices
type PriceTotal = Price;

type WeightPerUnit = Weight; // needed to meet truck constraints

type RegionId = Nat; // xxx variant type?


//
// Unique Ids
// ----------
// Internally, each type of Id serves as a "row key" for a table (or two).
//

type ProduceId = Nat;
type ProducerId = Nat;
type RetailerId = Nat;
type TruckTypeId = Nat;
type InventoryId = Nat;
type TransporterId = Nat;
type RouteId = Nat;
type OrderId = Nat;

//
// Query parameters and results
// ----------------------------
//

type OrderInfo = shared {
produce: ProduceId;
producer: ProducerId;
quant: Quantity;
ppu: PricePerUnit;
transporter: TransporterId;
truck_type: TruckTypeId;
weight: Weight;
region_begin:RegionId;
region_end: RegionId;
date_begin: Date;
date_end: Date;
prod_cost: PriceTotal;
trans_cost: PriceTotal;
};

// xxx same as an OrderInfo? If different, then how?
type QueryAllResult = shared {
produce: ProduceId;
producer: ProducerId;
quant: Quantity;
ppu: PricePerUnit;
transporter: TransporterId;
truck_type: TruckTypeId;
weight: Weight;
region_begin:RegionId;
region_end: RegionId;
date_begin: Date;
date_end: Date;
prod_cost: PriceTotal;
trans_cost: PriceTotal;
};

// xxx how to represent huge result messages?
type QueryAllResults = [QueryAllResult];

// the "Service"
actor ProduceExchange {

// Producer-based ingress messages:
// ================================

producerAddInventory(
prod: ProduceId,
quant:Quantity,
ppu: PricePerUnit,
begin:Date,
end: Date,
) : async ?InventoryId {
// xxx
null
};

producerRemInventory(id:InventoryId) : async ?() {
// xxx
null
};

producerOrders(id:ProducerId) : async ?[OrderId] {
// xxx
null
};

// Transporter-based ingress messages:
// ===================================

transporterAddRoute(
trans: TransporterId,
rstart: RegionId,
rend: RegionId,
start: Date,
end: Date,
cost: Price,
tt: TruckTypeId
) : async ?RouteId {
// xxx
null
};

transporterRemRoute(id:RouteId) : async ?() {
// xxx
null
};

transporterOrders(id:TransporterId) : async ?[OrderId] {
// xxx
null
};

// Retailer-based ingress messages:
// ===================================

retailerQueryAll(id:RetailerId) : async ?QueryAllResults {
// xxx
null
};

retailerPlaceOrder(
id:RetailerId,
inventory:InventoryId,
route:RouteId) : async ?OrderId
{
// xxx
null
};

retailerOrders(id:RetailerId) : async ?[OrderId] {
// xxx
null
};

// (Producer/Transporter/Retailer) ingress messages:
// ========================================================

orderInfo(id:OrderId) : async ?OrderInfo {
// xxx
null
};

};
Loading