# Planning Weekly Workouts in 100 lines of Haskell

DevFeed: [Planning Weekly Workouts in 100 lines of Haskell](<https://devfeed.tech/articles/planning-weekly-workouts-in-100-lines-of-haskell-27916.md>)

Original publisher: [Read original article](<http://alt-romes.github.io/posts/2024-08-14-planning-a-workout-week-with-100-lines-of-haskell.html>)

Published: 2024-08-14T00:00:00Z

Content type: tutorial

Language: en

Sources: [Romes' Musings](<https://devfeed.tech/sources/romes-musings.md>)

Topics: [Haskell](<https://devfeed.tech/topics/haskell.md>), [Programming](<https://devfeed.tech/topics/programming.md>), [Code](<https://devfeed.tech/topics/code.md>)

Tags: [code](<https://devfeed.tech/tags/code.md>), [haskell](<https://devfeed.tech/tags/haskell.md>), [programming](<https://devfeed.tech/tags/programming.md>), [script](<https://devfeed.tech/tags/script.md>)

## AI overview

A short tutorial demonstrates how to build a standalone 100-line Haskell workout planner using the logict logic-programming monad. The program generates weekly schedules satisfying running and bodyweight-exercise constraints.

## Source excerpt

Contents 1 A workout planner in 100 lines of Haskell I have recently started doing some outdoors bodyweight workouts. I also want to start running again, but I'm recovering from a minor knee injury until the start of next month. Tonight I decided to put together a weekly schedule to start following next month. The first pen and paper versions were fine, but I wasn't completely satisfied. The next logical step was to write a quick program to see what possible plans I was missing. The schedule must satisfy a few constraints, but the core of it is that I should do, every week, on one axis, one short run (high-intensity) and one long run (long distance), and, on the other axis, have two pull days (as in pull-ups), two push days (as in push-ups), and two leg days (as in squats). Finding a weekly workout that satisfies certain constraints is an answer-set-programming kind of problem, best solved by some kind of logic programming. Rather than turning to Prolog or Clingo, I decided to just stick to Haskell and use the logic-programming monad from logict! 1 A workout planner in 100 lines of Haskell What follows is mostly just the demonstration of using logict applied to this particular problem. I believe the weeklySchedule function can be easily understood in general, even by anyone unfamiliar with Haskell and/or logic programming - and that's the meat of this short post and program. Note that the program is a cabal shell script which can be run by executing the script file (as in ./ScheduleExercise, as long as cabal is in path). It is standalone, and exactly 100 lines (with comments, shebangs and everything). Feel free to try and modify it! #!/usr/bin/env cabal {- cabal: build-depends: base, logict -} import Control.Applicative import Control.Monad import Control.Monad.Logic import Data.List import Data.Maybe workout = ["Push day", "Pull day", "Leg day", "No workout"] running = ["Long run", "Short run", "No run"] weekdays = ["Seg.", "Ter.", "Qua.", "Qui.", "Sex.", "Sab.", "