Skip to content

Implement previews#64

Open
nimec01 wants to merge 3 commits intofmidue:fmiduefrom
nimec01:previews
Open

Implement previews#64
nimec01 wants to merge 3 commits intofmidue:fmiduefrom
nimec01:previews

Conversation

@nimec01
Copy link
Copy Markdown
Collaborator

@nimec01 nimec01 commented Apr 1, 2026

This pull request implements previews that allow us to show preview images of incomplete programs.

Example:

import CodeWorld

{-| Draw something -}
main :: IO ()
main = drawingOf (translated 5 undefined (circle 3) & undefined)

will produce this image:
image

The feature can be enabled per-request by adding a enablePreview field to the /compile request that has value true. It can also be enabled by default via a config setting. The field value in the request will then override the default.

The config path can be set via the CONFIG_PATH environment variable. The content of the config.yaml would then look like this:

preview:
  enabledByDefault: false
  defaultHoleValues:
    Double: "0"
    Color: "black"
    Picture: "blank"

(My further goal is to replace the extensions.yaml config file by a field in this new consolidated config.)

A few questions left:

  • Should this also work in the non-Haskell mode? (It currently does not)
  • Should the user be able to configure this itself in the editor?

@nimec01 nimec01 requested a review from jvoigtlaender April 1, 2026 10:08
@jvoigtlaender
Copy link
Copy Markdown
Member

  • Should this also work in the non-Haskell mode? (It currently does not)

No, that’s not needed.

  • Should the user be able to configure this itself in the editor?

I wasn’t envisioning this in the editor-and-compile-view, at least not originally. My idea was to use this feature in the post-to-API-to-get-a-display-without-code.

About the configurable hole-filling: does this also allow for „undefined :: Double -> Picture“? (which could be replaced by „const blank“)

@nimec01
Copy link
Copy Markdown
Collaborator Author

nimec01 commented Apr 1, 2026

About the configurable hole-filling: does this also allow for „undefined :: Double -> Picture“? (which could be replaced by „const blank“)

The regular expression should not cover that currently. I'll try to update it.

@nimec01 nimec01 marked this pull request as ready for review April 1, 2026 11:17
@nimec01
Copy link
Copy Markdown
Collaborator Author

nimec01 commented Apr 1, 2026

Function holes are now supported as well. Config would then look like this:

preview:
  defaultHoleValues:
    "Double -> Picture": "const blank"
    "Double": "0"

@jvoigtlaender
Copy link
Copy Markdown
Member

Wie robust ist das gegen Vorkommen von „undefined“ im Programmtext, die gar nicht für Prelude.undefined stehen, sondern etwa „let undefinedNumber = 42 in whatever“ oder einen String, der „undefined“ enthält?

Sollte vielleicht zumindest gecheckt werden, dass der GHC genau so viele typed holes meldet, wie man vorher „undefined“ durch „_“ ersetzt hat?

then pure (status, res)
else do
let sourceWithHoles = T.replace "undefined" "_" source
(status',res') <- liftIO $ runCompile ctx programId mode sourceWithHoles
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Das heißt, ein weiterer Compile wird selbst dann durchgeführt, wenn überhaupt keine Ersetzungen vorgenommen wurden (weil keine undefineds vorkamen)?

Das sollte sicher optimiert werden.

@jvoigtlaender
Copy link
Copy Markdown
Member

Anschließend: fmidue/haskell-template-task#40

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants