google / google/codeworld

Reflex as a backend for all CodeWorld programs

Offen
#1,040 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen
cleanup
Vorherrschende Sprache
Haskell
Sterne
1.3k
Forks
201
PR-Merge-Kennzahlen
Keine gemergten PRs in 30 T.

Beschreibung

After #1038 is done, it will become feasible to implement the traditional CodeWorld entry points in terms of the new Reflex backend. The existing entry points will behave the same as they do today, but instead of more hand-coded event loops, they will translate their input to FRP.

Naively, something like this would do it:

```haskell
import qualified CodeWorld.Reflex as CW.R
import qualified Reflex as R

import CodeWorld hiding (drawingOf, animationOf, activityOf)

drawingOf :: Picture -> IO ()
drawingOf pic = CW.R.reflexOf $ const $ return $ R.constDyn pic

animationOf :: (Double -> Picture) -> IO ()
animationOf frame = CW.R.reflexOf $ \input ->
return (frame <$> CW.R.currentTime input)

activityOf :: a -> (Event -> a -> a) -> (a -> Picture) -> IO ()
activityOf initial change picture = CW.R.reflexOf $ \input -> do
let events = R.mergeWith (.) [
change <$> KeyPress <$> CW.R.keyPress input,
change <$> KeyRelease <$> CW.R.keyRelease input,
change <$> TextEntry <$> CW.R.textEntry input,
change <$> PointerPress <$> CW.R.pointerPress input,
change <$> PointerRelease <$> CW.R.pointerRelease input,
change <$> PointerMovement <$> R.updated (CW.R.pointerPosition input),
change <$> TimePassing <$> CW.R.timePassing input
]
state <- R.foldDyn ($) initial events
return (picture <$> state)
```

The real world is not so clean, though.

* There are debug controls that cannot be implemented for arbitrary reflex programs, such as the time-traveling debugger. These will need to be implemented at the translation layer instead.
* Time-step elision is an optimization performed by observing sharing in the `change` function to learn about whether events need to be delivered, or the screen redrawn. It needs to be implemented in the transition, as well.
* `groupActivityOf` is still an open question. It has its own implementation anyway (this is why it has never even supported inspection), but it would be awesome if it could also be implemented in the same framework.

Beitragsleitfaden

Beitragsleitfaden öffnen

Rechercherichtung

Beginne mit der Durchsicht von Issue #1038 und den bestehenden traditionellen CodeWorld-Einstiegspunkten, insbesondere drawingOf, animationOf, activityOf und groupActivityOf. Ermittle, wie die Reflex-Übersetzung das aktuelle Verhalten beibehalten und gleichzeitig Debug-Steuerungen sowie das Weglassen von Zeitschritten behandeln sollte. Als erledigt gilt die Aufgabe, wenn die Einstiegspunkte das Reflex-Backend verwenden und der Ansatz für groupActivityOf geklärt ist.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
haskell
Bereich
backend
Issue-Typ
Feature
Schwierigkeit
5/5
Geschätzter Aufwand
Über eine Woche
Aktivitätsstatus
Veraltet
Klarheit
Muss geklärt werden
Anfängerfreundlichkeit
25/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.