编辑:Void我的意思是Haskell的Void类型,即不能有值的空类型undefined.
有关Swift Evolution的讨论是否noreturn要用实际Void类型替换函数属性.要做到这一点,我们必须确保这将为平台带来真正的好处.使用Void返回类型是不够的.
所以我请你提供非常实用的例子,其中使用Void增加了代码的清晰度,简洁性和通用性.也许它会使用类(在Haskell意义上),也许是泛型,也许它将包含Void在ADT中.
但是,请不要太过深入HKT,Monads,所有那些高级别的东西.标准库中的实用程序功能也是一个不好的例子.一个完美的例子将是街机游戏的一部分或类似的东西.
I've split my pancakes Gradle-based library written in Kotlin into multiple modules: pancakes-core, pancakes-addon1, ..., pancakes-addonN. The addon ones include the core one.
Now, most users shouldn't care and will just want the default configuration with all the dependencies included. But they will have to write boilerplate:
dependencies {
implementation("pancakes:pancakes-core")
implementation("pancakes:pancakes-addon1")
...
implementation("pancakes:pancakes-addonN")
}
Run Code Online (Sandbox Code Playgroud)
This is a no-go for me. I'll probably have to merge all the modules, although I've just spent some time to branch off …
我正在开发一个协程多生产者、单消费者Event(这里是,用于上下文)。简化:
class WaitList {
public:
void Append() { coro_.store(GetCurrentCoro()); }
void Remove() { coro_.store({}); }
void WakeUp() {
auto p = coro_.exchange({});
if (p) p->WakeUpIfSleeping();
}
private:
std::atomic<Coro*> coro_{nullptr};
};
class Event {
public:
void Wait() {
waiters_.Append();
if (IsReady()) waiters_.WakeUp();
// fall asleep
// ...
// woken up
waiters_.Remove();
}
void Send() {
SetReady();
waiters_.WakeUp();
}
private:
bool IsReady() { return signal_.load(); }
void SetReady() { return signal_.store(true); }
WaitList waiters_;
std::atomic<bool> signal_{false};
};
Run Code Online (Sandbox Code Playgroud)
请帮我设置以下最低要求 …
atomic ×1
c++ ×1
curry-howard ×1
gradle ×1
haskell ×1
kotlin ×1
memory-model ×1
multi-module ×1
type-systems ×1
types ×1