From 8ff37e0a47d82acde264075f21e2260a6c1a8b79 Mon Sep 17 00:00:00 2001 From: dos-reis Date: Wed, 22 May 2013 00:52:15 +0000 Subject: * algebra/aggcat.spad.pamphlet (ShallowlyMutableAggregate): Extend Aggregate only. Adjust users. (BagAggregate): Explicitly extend HomogeneousAggregate. (AssociationListAggregate): Extend ShallowlyMutableAggregate. --- src/algebra/aggcat.spad.pamphlet | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) (limited to 'src/algebra/aggcat.spad.pamphlet') diff --git a/src/algebra/aggcat.spad.pamphlet b/src/algebra/aggcat.spad.pamphlet index 512bf628..473cfd2c 100644 --- a/src/algebra/aggcat.spad.pamphlet +++ b/src/algebra/aggcat.spad.pamphlet @@ -190,7 +190,7 @@ FiniteAggregate(S: Type): Category == Exports where ++ that support in place mutation that do not change their general ++ shapes. ShallowlyMutableAggregate(S: Type): Category == Exports where - Exports == HomogeneousAggregate S with + Exports == Aggregate with map!: (S->S,%) -> % ++ \spad{map!(f,u)} destructively replaces each element ++ \spad{x} of \spad{u} by \spad{f(x)} @@ -275,7 +275,7 @@ import List ++ and where the order in which objects are inserted determines the order ++ of extraction. ++ Examples of bags are stacks, queues, and dequeues. -BagAggregate(S:Type): Category == ShallowlyMutableAggregate S with +BagAggregate(S:Type): Category == Join(HomogeneousAggregate S,ShallowlyMutableAggregate S) with bag: List S -> % ++ bag([x,y,...,z]) creates a bag with elements x,y,...,z. extract!: % -> S @@ -1095,6 +1095,7 @@ TableAggregate(Key:SetCategory, Entry:SetCategory): Category == table l == dictionary l -- empty() == dictionary() + insert!(p,t) == (t(p.key) := p.entry; t) indices t == keys t coerce(t:%):OutputForm == @@ -2546,10 +2547,11 @@ import ListAggregate ++ as a table. It is a poor mans version of a table: ++ searching for a key is a linear operation. AssociationListAggregate(Key:SetCategory,Entry:SetCategory): Category == - Join(TableAggregate(Key, Entry), ListAggregate Record(key:Key,entry:Entry)) with - assoc: (Key, %) -> Maybe Record(key:Key,entry:Entry) - ++ assoc(k,u) returns the element x in association list u stored - ++ with key k, or \spad{nothing} if u has no key k. + Join(TableAggregate(Key, Entry),ListAggregate Record(key:Key,entry:Entry),_ + ShallowlyMutableAggregate Entry) with + assoc: (Key, %) -> Maybe Record(key:Key,entry:Entry) + ++ assoc(k,u) returns the element x in association list u stored + ++ with key k, or \spad{nothing} if u has no key k. @ -- cgit v1.2.3