Discussion:
[Haskell-cafe] Feedback on plan for checking code requirements in a GHC plugin
Chris Smith
2018-11-20 18:46:31 UTC
Permalink
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:
https://code.world/haskell#PpwpTF1wv3qIvwhohCfvSrQ

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?

Thanks,
Chris
Shao Cheng
2018-11-21 02:59:00 UTC
Permalink
Hi Chris,

For "checking static properties at compile time", you may find [sbvPlugin](
https://hackage.haskell.org/package/sbvPlugin) useful, it supports
annotating functions with ANN pragmas that declare properties verifiable by
an SMT solver. I haven't used it with ghcjs so not sure if it fits your use
case, but probably worth a try.

Regards,
Shao Cheng
Post by Chris Smith
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
https://code.world/haskell#PpwpTF1wv3qIvwhohCfvSrQ
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?
Thanks,
Chris
_______________________________________________
Haskell-Cafe mailing list
http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
Only members subscribed via the mailman list are allowed to post.
Johannes Waldmann
2018-11-21 13:28:07 UTC
Permalink
Post by Chris Smith
Has anyone done anything like this before?
Sort-of. Not with a GHC plugin, but haskell-src-exts to get the AST,
and then match with a blueprint for the code
(students have to replace "undefined" by some expression).
See "How I Teach Functional Programming" (WFLP 2017)
https://www.imn.htwk-leipzig.de/~waldmann/talk/

- J.W.
Matthew Pickering
2018-11-21 17:04:43 UTC
Permalink
Nothing to add other than this sounds just like the sort of thing that
will be easy to implement as a source plugin.

You might find my plugins resource page useful:
http://mpickering.github.io/plugins.html

In particular, this post about how to construct expressions:
http://mpickering.github.io/posts/2018-06-11-source-plugins.html

Cheers,

Matt
Post by Chris Smith
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: https://code.world/haskell#PpwpTF1wv3qIvwhohCfvSrQ
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?
Thanks,
Chris
_______________________________________________
Haskell-Cafe mailing list
http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
Only members subscribed via the mailman list are allowed to post.
Loading...