No slash command · from haskell-tasuke
Avoid overusing threadDelay because time-dependent code is unstable and unportable. Prefer synchronization variables like TMVar or retry combinators. Use when writing or reviewing Haskell code that delays threads, waits, or polls.
Ships in haskell-tasuke. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
threadDelaythreadDelayはスレッドを指定した時間だけ遅延させる関数です。
threadDelayを乱用するのはやめましょう。
時間に依存するコードは安定性や移植性が低いためです。
次の実行でも同じ時間で処理が完了するとは限りません。 他のマシンでは同じ時間で処理が完了しないかもしれません。
また必然的にその時間だけ実行がストップしてしまうので、 待つように命令した分だけ実行が遅くなります。
TMVarなどの同期変数が使える場合は正確に同期できます。
Haskellの別のスレッドの実行を待つ場合などに使えます。
言語外部のデータやイベントに依存する場合は、 retry: Retry combinators for monadic actions that may fail パッケージなどを使って細かくリトライしてください。
短い単位の繰り返しからだんだん待機時間を増やしていくことで、 固定の待機をするよりは実行のストップが短くなることが見込めます。 また最大待機時間の値を固定値より大きくすることが許容できるため、 実行の安定も見込めます。
リトライポリシーとしては、
ネットワークを経由する場合は、
基本的にfullJitterBackoffを使うのが望ましいでしょう。
待機時間を増やしていきますし、
乱数を入れることで複数の端末が衝突することをある程度避けることが出来ます。
MonadIOの文脈を入れたくないとか、
もう少しシンプルでもいいなら、
exponentialBackoffも選択肢になります。
固定でなければ不都合がある場合はconstantDelayを使うべきです。
全体の待機可能な時間はlimitRetriesByCumulativeDelayで制限してください。
以下のように意図的に永久的にスレッドを停止する場合は問題ありません。
forever $ threadDelay maxBound
そのスレッドが持つリソースを、 GCに回収されないように保持するために、 こういった永久的なsleepが必要な時もあります。
テストコードを書く時に、 ロジックに実行を待つ部分が実装されていない場合などは、 同期変数を組み込むとロジックを複雑にしてしまうことがあるので仕方ない時もあります。
テストコードなら壊れても致命的ではないので許容することもありますが、 やはり他の方法を使えないか検討するべきです。
とりあえずretry系統を使えばだいたいの場合はthreadDelayを使うよりはマシになるでしょう。
What SKILL.md sets; muted values are Claude Code's defaults
Other plugins' skills for the same job
npx claudepluginhub ncaq/konoka --plugin haskell-tasuke19 skills in this plugin
/bracketUse bracket or with-style functions to guarantee resource cleanup even on exceptions instead of separate do blocks. Use when writing or reviewing Haskell code that acquires and releases resources./bump-cabal-index-stateUpdate Cabal project index-state to the latest timestamp. Use when it needs to bump the cabal index-state./cabal-commandUse cabal with --disable-optimization for development builds and tests, and add --enable-tests to avoid rebuilds. Use when running or suggesting cabal build or test commands in Haskell development./exceptionDo not throw exceptions from pure code with error or throw, give exceptions structured types, and never silently swallow errors in IO. Use when writing or reviewing Haskell error handling, exceptions, or IO code./exportExplicitly enumerate Haskell module exports instead of exporting everything implicitly, and use re-export sparingly. Use when writing or reviewing Haskell module export lists./function-resultDo not discard a function's final value with return (), pure (), or void; adjust the type to return the value and let the caller discard it when unneeded. Use when writing or reviewing Haskell functions that return unit or discard results.