Skip to content

Instantly share code, notes, and snippets.

@anacrolix
Created February 24, 2026 23:13
Show Gist options
  • Select an option

  • Save anacrolix/5baf577dfc61bf8fa9b4786dca7dc6b2 to your computer and use it in GitHub Desktop.

Select an option

Save anacrolix/5baf577dfc61bf8fa9b4786dca7dc6b2 to your computer and use it in GitHub Desktop.

Prelude cleanup issues

  1. Either class has ok/err backwards for Result — The impl Either (Result e a) maps ok to the Ok case and err to Err, but either conventionally takes the left/error handler first: either : (a -> c) -> (b -> c) -> Either a b -> c -- ^left ^right
  2. Your Result impl has either ok err which reads as "ok handler first, err handler second" — but in walk line 78 you write either (each ...) (readDirErr path) where the first arg handles the Ok case (the list of names). So the naming is internally consistent with your usage, but reversed from the Haskell convention where the left/error case comes first.
  3. Either class signature — either : (a -> c) -> (b -> c) -> c is missing Self — it should probably be either : (a -> c) -> (b -> c) -> Self -> c or use Self-position dispatch. As written, a, b, c are unbound.
  4. The old walk function-based version (lines 68-92 from before) is gone — replaced by the effect-based one. Good.
  5. if (.isDir fileInfo) return () on line 76 — this looks inverted. You want to recurse into directories, not skip them. Should be if (not <| .isDir fileInfo) return ().
  6. readDirErr on line 78 — needs to be qualified as Walk.readDirErr like Walk.visit on line 74, or is it meant to be unqualified?

examples/scripts/walk.shit — replacing lsR

Line 2 uses lsR path which no longer exists. The simple case (list all files recursively) using the effect-based walk with handle:

handle (walk path) with { visit p res resume -> print p | _ -> resume (); recurse p info resume -> resume true; readDirErr p err resume -> resume false }

This is more efficient than the old lsR — it prints as it walks rather than building and returning a giant list. The du-big-files.shit already demonstrates this streaming pattern with Yield.

du-big-files.shit — could use walk

This script manually reimplements directory traversal. It could be rewritten using the effect-based walk:

handle (walk root) with { visit p res resume -> res | either (\info -> if (not <| .isDir info && .size info > threshold) then (yield { path: p, size: .size info } | _ -> resume ()) else resume ()) (_ -> resume ()); recurse p info resume -> resume true; readDirErr p err resume -> resume false }

Though this mixes Walk and Yield effects — not sure if your runtime supports nested effect handlers cleanly enough for that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment