From d07fc9735f40e545edda456e15dbab783c500f6a Mon Sep 17 00:00:00 2001 From: Gabriel Dos Reis Date: Sun, 17 Jan 2016 22:53:01 -0800 Subject: subtractIfCan$CancellationAbelianMonoid: return the more principled Maybe % --- src/algebra/prtition.spad.pamphlet | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) (limited to 'src/algebra/prtition.spad.pamphlet') 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 -- cgit v1.2.3