Hazel
October 28, 2021, 11:39pm
1
I stumbled across this which contains a neat pattern I could currently use. However I’m getting
type error [M0077], a shared function is only allowed as a public field of an actor (This is a limitation of the current version.)
at compile.
Is this still a planned feature?
1 Like
claudio
October 29, 2021, 11:06am
2
You mean this line, right?
plate : Text;
isValid : Bool;
wasStolen : Bool;
expires : Nat;
};
actor class PACars(dmv : DMV) {
public func verifyCarInformation(user : User, car : Car) : async ?(shared (Location, TimeSpan) -> async Result) {
let carInfo = await dmv.check(car);
if (carInfo.isValid and not carInfo.wasStolen) {
return ?(shared func (location : Location, time : TimeSpan) : async Result {
return reserveSpot(user, carInfo, location, time);
})
} else {
return null;
}
};
private func reserveSpot(user : User, carInfo : CarInfo, location : Location, timeSpan : TimeSpan) : Result {
// Do the actual work of registering the parking spot for the
// given car in the given time span
This is returning an anonymous shared function that closes over some local data.
Yeah, it’s unlikely we will support that any time soon, though its actually related to the discussion on thunks here. We would need both private entry points (not supported by the IC) and, ideally, unforgeable closures as candid values.
Curiously, this is related to @rossbergs suggestions here
opened 05:10PM - 02 Aug 21 UTC
I've recently been frustrated by Motoko's inability to do raw calls as seen in t… he cycle wallet(https://github.com/dfinity/cycles-wallet/blob/5725370020593bd744ddbc589c117d76d6ca8ae4/wallet/src/lib.rs#L625).
To be able to do this I would imagine motoko would need to:
- expose the raw call
- enable some kind of type reflection
- formalize some kind of serialization/deserialization
I've seen some mention of these in some of the open/closed meta-issue issues here and I thought I'd stand on top of the building yelling to hopefully get these some attention. :)
What I don't want to do is to have to create a function on every motoko pass through canister called __forwardCall(principal: Principal; method: text, args: [Nat8]/WorkSpace/[DataZones]) and have to have every canister handle a __handleForwardCall that deserializs all the parameters manually into known types and organize the community to universally add these to their canisters. perhaps there is a compiler way to automate this kind of thing? Seems overkill when the underlying functions can just be exposed some how.
1 Like
Hazel
October 29, 2021, 2:46pm
3
Apologies should have included the link! Yes thats the one.
claudio:
Yeah, it’s unlikely we will support that any time soon, though its actually related to the discussion on thunks here. We would need both private entry points (not supported by the IC) and, ideally, unforgeable closures as candid values.
Lots of fun technical challenges . Would be wonderful to have in the future but I don’t think it’s 100% necessary.
Thanks!