diff options
author | Gabriel Dos Reis <gdr@axiomatics.org> | 2016-01-17 18:17:04 -0800 |
---|---|---|
committer | Gabriel Dos Reis <gdr@axiomatics.org> | 2016-01-17 18:17:04 -0800 |
commit | 5437d438937eb25eb320fef6e4fd6ebc91ca6dc9 (patch) | |
tree | d214a8fbc698b2aefe005c0c7ffe75ed4e6d338c /src/algebra | |
parent | 5950f07335c0a2f38224e0223951f9cf6fca350b (diff) | |
download | open-axiom-5437d438937eb25eb320fef6e4fd6ebc91ca6dc9.tar.gz |
Maybe: CoercibleTo OutputForm is now optional.
Diffstat (limited to 'src/algebra')
-rw-r--r-- | src/algebra/any.spad.pamphlet | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/src/algebra/any.spad.pamphlet b/src/algebra/any.spad.pamphlet index 4af9f557..963fab05 100644 --- a/src/algebra/any.spad.pamphlet +++ b/src/algebra/any.spad.pamphlet @@ -69,8 +69,8 @@ import Boolean ++ Description: ++ This domain implements the notion of optional value, where ++ a computation may fail to produce expected value. -Maybe(T: CoercibleTo OutputForm): Public == Private where - Public == Join(UnionType,RetractableTo T, CoercibleTo OutputForm) with +Maybe(T: Type): Public == Private where + Public == Join(UnionType,RetractableTo T) with just: T -> % ++ \spad{just x} injects the value `x' into %. case: (%,[| T |]) -> Boolean @@ -83,6 +83,7 @@ Maybe(T: CoercibleTo OutputForm): Public == Private where ++ compiler in case it knows that `x' really is a \spadtype{T}. nothing: % ++ \spad{nothing} represents failure or absence of value. + if T has CoercibleTo OutputForm then CoercibleTo OutputForm Private == add import %nothing: % from Foreign Builtin import %peq: (%,%) -> Boolean from Foreign Builtin @@ -95,9 +96,10 @@ Maybe(T: CoercibleTo OutputForm): Public == Private where retractIfCan x == x case T => x@T "failed" - coerce(x: %): OutputForm == - x case nothing => paren(empty()$OutputForm)$OutputForm - (x@T)::OutputForm + if T has CoercibleTo OutputForm then + coerce(x: %): OutputForm == + x case nothing => paren(empty()$OutputForm)$OutputForm + (x@T)::OutputForm @ |