Planning Weekly Workouts in 100 lines of Haskell

11 Likes

Thanks for sharing! :slight_smile:

2 Likes

Nice, thanks for sharing! However, I can’t help but notice that the solution is heavy on string usage. I really expected these to be ADTs

workout = ["Push day", "Pull day", "Leg day", "No workout"]
running = ["Long run", "Short run", "No run"]
weekdays = ["Seg.", "Ter.", "Qua.", "Qui.", "Sex.", "Sab.", "Dom."]

At least that’s what my Haskell instinct tells me when I look at these lists :slight_smile:

1 Like

That’s right, I would have done that for any proper program too. Given the more general audience and format I was targeting, and the scripty nature of it, this approach seemed fine enough though, and a runtime error here is costless :slight_smile:.

1 Like

The heavy lifting is done by the logict package.

I think that’s too much credit to logict, my suspicion is that pretty much everything in the post can use the normal list monad without an issue. I cannot spot any calls to (>>-) or interleave.

1 Like

so IIUC interleave should be used instead of (<|>) to search down both branches at equal rate?

1 Like

Yes, interleave instead of (<|>) (but not in the definition of choose) and some (but likely only some!) of implicit monadic (>>=) should be replaced by (>>-).

1 Like