[Haskell-cafe] Feedback on plan for checking code requirements in a GHC plugin

Chris Smith cdsmith at gmail.com
Tue Nov 20 18:46:31 UTC 2018

Hey everyone,

I'm converging on a design for a new feature of CodeWorld, the
Haskell-based educational programming environment that I teach with.  I'm
wondering if anyone has done something like this before.

The goal is that when I give an assignment in a class (e.g., "modify this
starting code to generalize the repeated pattern using a function"), I want
the user to see a checklist of assignment requirements when they run the
code.  A prototype implementation is here:

There are all sorts of possible requirements, such as: "No lines longer
than 80 characters", or "there must be a function called foo", or "all
top-level definitions must have type signatures", or "your code must define
at least 10 top-level variables, and use at least 3 where clauses", or
"your definition of var should be equivalent to this one" (see Joachim
Breitner's inspection testing work), or even "the function f must satisfy
this QuickCheck property".  It's been suggested that the requirements
language also include the ability to match patterns in the AST, which I
think is a good idea.

The current prototype uses a pre-compile step that parses the code using
haskell-src-exts, and doesn't implement dynamic requirements
(runtime-evaluated) at all.  My ultimate plan, though, is to send these
requirements to GHC via a plugin, then have it evaluate the static ones at
compile time, and generate code to check the dynamic ones.  Finally, the
plugin would add new code to the beginning of main that will invoke a
configurable function with the results of the requirement check
(hard-coding the static ones, and evaluating dynamic ones on the fly).  (In
the CodeWorld environment, this function would display the checklist in the
web UI, for example.)

Has anyone done anything like this before?  Any wisdom to share, or ideas
to contribute?

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/haskell-cafe/attachments/20181120/d392b6c2/attachment.html>

More information about the Haskell-Cafe mailing list