diff options
author | Gabriel Dos Reis <gdr@axiomatics.org> | 2016-01-17 22:53:01 -0800 |
---|---|---|
committer | Gabriel Dos Reis <gdr@axiomatics.org> | 2016-01-17 22:53:01 -0800 |
commit | d07fc9735f40e545edda456e15dbab783c500f6a (patch) | |
tree | 4d9fab82a7085b73a4b00d23389935503fdfc90d /src/algebra/prtition.spad.pamphlet | |
parent | 5437d438937eb25eb320fef6e4fd6ebc91ca6dc9 (diff) | |
download | open-axiom-d07fc9735f40e545edda456e15dbab783c500f6a.tar.gz |
subtractIfCan$CancellationAbelianMonoid: return the more principled Maybe %
Diffstat (limited to 'src/algebra/prtition.spad.pamphlet')
-rw-r--r-- | src/algebra/prtition.spad.pamphlet | 17 |
1 files changed, 9 insertions, 8 deletions
diff --git a/src/algebra/prtition.spad.pamphlet b/src/algebra/prtition.spad.pamphlet index 6fc92821..56acfbda 100644 --- a/src/algebra/prtition.spad.pamphlet +++ b/src/algebra/prtition.spad.pamphlet @@ -91,17 +91,18 @@ Partition(): Exports == Implementation where zero? n => 0 x + (subtractIfCan(n,1) :: NNI) * x - remv(i: PI,x: %): UN == - member?(i,rep x) => per remove(i, rep x)$Rep - "failed" + remv(i: PI,x: %): Maybe % == + member?(i,rep x) => just per remove(i, rep x)$Rep + nothing subtractIfCan(x, y) == zero? x => - zero? y => 0 - "failed" - zero? y => x - (aa := remv(first rep y,x)) case "failed" => "failed" - subtractIfCan((aa :: %), per rest rep y) + zero? y => just 0 + nothing + zero? y => just x + aa := remv(first rep y,x) + aa case nothing => nothing + subtractIfCan(aa@%, per rest rep y) powers x == l := rep x |