-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Miscellaneous #121
Miscellaneous #121
Conversation
No description provided. |
src/CertifiedData.mo
Outdated
@@ -32,7 +32,9 @@ module { | |||
/// | |||
/// See a full example on how to use certified variables here: https://github.com/dfinity/examples/tree/master/motoko/cert-var | |||
/// | |||
public let set : (data : Blob) -> () = Prim.setCertifiedData; | |||
public func set<system>(data : Blob) : () { | |||
Prim.setCertifiedData(data) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess we may need to make the Prim.setCertifiedData take a argument too to make this really safe (otherwise people can directly call Prim.setCertifiedData).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doing this change may also break some third party libraries. But I guess we need to make break some eggs...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess we may need to make the Prim.setCertifiedData take a argument too to make this really safe
This is probably worth doing, since otherwise there isn't much of a benefit to changing the base library if people can go around it by importing Prim
directly.
I'll roll this back to set : (data : Blob) -> () = Prim.setCertifiedData
so that it preserves whether the prim function has the <system>
requirement.
/// ``` | ||
public func equalWithin(x : Float, y : Float, epsilon : Float) : Bool { | ||
public func equal(x : Float, y : Float, epsilon : Float) : Bool { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@luc-blaeser are you ok with renaming equalWIthin (and notEqualWithin) to equal and notEqual?
Also another option might be to make both of these curried functions, that take the epsilon as a first argument and return an equality/inequality function of the usual binary type:
public func equalWithin(epsilon: Float) : (x : Float, y : Float) - > Bool =
func(x : Float, y: float) { ... epsilon ... }
}
(and similarly for nonEqualWithin
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The motivation here is for API uniformity. I suppose we could curry the arguments, although I think equal(x, y, epsilon)
is more consistent with how we handle the compare
and equal
functions for data structures.
On the other hand, it could be worth doing something different to reduce possible confusion about the argument order, given the equal(Float, Float, Float)
signature.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right, I thinking about the situation where you want to pass the equality function as a first-class argument (which is why we define it for convenience...)
I don't have a strong opinion...
@@ -22,29 +22,4 @@ module { | |||
ha == hb | |||
}; | |||
|
|||
/// Computes a hash from the least significant 32-bits of `n`, ignoring other bits. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we aren't going to even provide any hash based data structures (are we?) I'd be tempted to get rid of this whole module Hash.mo
. length
seemes misnamed (should be maxBitIndex or something) and bit
is probably an implementation detail of Trie.mo
which uses the hash bits to index into a radix tree (IIRC). Might be worth checking if pos/length are used anywhere else.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Opened a separate PR for this: #129.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM (see suggestions)
Co-authored-by: Claudio Russo <claudio@dfinity.org>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. We can always change the equal notEqual names back if @luc-blaeser feels strongly.
/// ``` | ||
public func notEqualWithin(x : Float, y : Float, epsilon : Float) : Bool { | ||
not equalWithin(x, y, epsilon) | ||
public func notEqual(x : Float, y : Float, epsilon : Float) : Bool { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we even want notEqual
, since its the literal negation of equal
@luc-blaeser and we don't provide notEqual
for other primitive types.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems reasonable to remove this function. I'll merge and open another PR to start working on the merge conflicts in parallel.
<system>
capability to callCertifiedData.set()
.Timer
andError
modules to reflect changes to original base library.