google / google/codeworld

Reflex as a backend for all CodeWorld programs

Aperta
#1,040 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub
cleanup
Lingua principale
Haskell
Stelle
1.3k
Fork
201
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Descrizione

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.

Guida per i contributori

Apri la guida per i contributori

Direzione di ricerca

Inizia esaminando l’issue #1038 e gli attuali punti di ingresso tradizionali di CodeWorld, in particolare drawingOf, animationOf, activityOf e groupActivityOf. Determina come la traduzione Reflex debba preservare il comportamento attuale gestendo al contempo i controlli di debug e l’elisione dei passi temporali. Il lavoro è completato quando i punti di ingresso usano il backend Reflex e l’approccio di groupActivityOf è stato risolto.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
haskell
Ambito
backend
Tipo di issue
Funzionalità
Difficoltà
5/5
Tempo stimato
Più di una settimana
Stato di attività
Ferma
Chiarezza
Da chiarire
Idoneità per principianti
25/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.