No slash command · from haskell-tasuke
Prefer MonadIO and MonadUnliftIO type classes over using IO directly, and avoid redundant liftIO. Use when writing or reviewing Haskell IO actions, monad transformers, or type class abstractions.
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.
IOをなるべく直接使わず型クラスを使うIOモナドはプリミティブすぎます。
他のモナド変換子などと一緒に取り扱うのが不便です。
呼び出すたびにliftIOを使うのは面倒です。
なのでアクションを定義するときは出来る限りIOを直接使うのではなく、
MonadIOや、
MonadUnliftIOといった、
型クラスで抽象化するべきです。
MonadIOの方がより一般的なので、
先にそちらで定義出来ないか検討するべきです。
MonadUnliftIOの定義では、
class MonadIO m => MonadUnliftIO (m :: Type -> Type)
となっているため、
MonadUnliftIOのインスタンスは必ずMonadIOのインスタンスも持ちます。
なのでMonadUnliftIOの中でMonadIOの関数を呼び出すことはできるので、
MonadIOにすることに問題はありません。
MonadUnliftIOが要求される場合はそちらで定義してください。
IO内部でMonadUnliftIOのアクションを実行するMonadIOやMonadUnliftIOの文脈でIOのアクションを実行する場合はliftIOを使うだけで良いです。
IOの文脈でMonadUnliftIOのアクションを実行する場合はひと工夫必要な時があります。
以下の関数を使うことで解決できます。
askRunInIO :: MonadUnliftIO m => m (m a -> IO a)
askRunInIOをMonadUnliftIOの文脈で呼び出すことで、
MonadUnliftIOのアクションをIOに変換する関数を取得できます。
この関数をrunInIO関数などの名前で束縛して、
IOを要求するライブラリの型に対して、
MonadUnliftIOのアクションをrunInIOで包んで渡すことが出来ます。
または単発で済むならば以下の関数を使っても良いでしょう。
toIO :: MonadUnliftIO m => m a -> m (IO a)
liftIOの禁止既にMonadIO m => m aのような型を持っている関数を、
liftIOに渡しても問題なく動きますが、
無意味に冗長で読みにくいので、
liftIOなしでそのまま呼び出してください。
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.