Large programs tend to have multiple screens. For example, a Mario game might have a starting screen, a help screen, a settings screen, the game itself, and cut scenes. This is also true of presentations (each slide is a screen) wizard-style interfaces, and mobile phone apps.
Elm seems nice for writing a single screen, but not so great when you have multiple screens; you can't easily take a bunch of Elm programs and put them all together into a slideshow within Elm itself. The easiest way would be to do this outside Elm, either by putting programs on different HTML pages or by using JavaScript.
It might be possible to write a purely-functional framework for your slides (perhaps based on Automatons), but if you didn't have that in mind when you wrote each subprogram, you're faced with a big rewrite. Only the top-level program can use signals directly; the subprograms would have to be written some other way.
So maybe there should be a way to wrap up an Elm program into a command? Suppose we had something like this:
-- A scene is a command that runs to completion and outputs a value.
type Scene out
-- An external Elm program can be imported as a function from an input to a Scene.
-- For example:
myDialog : String -> Scene String
myDialog = importScene "path/to/dialog.elm"
-- A scene that does nothing but return a value
emptyScene : a -> Scene a
-- You can decide to play another Scene after the first one finishes
bindScenes : Scene a -> (a -> Scene b) -> Scene b
-- The main value of an Elm program can play a signal until it exits with a value, causing the
-- program to exit. The SceneFrame type allows the program to exit:
data SceneFrame a = Frame Element | Exit a
-- For example, the main value of a dialog might be:
main: String -> Signal (SceneFrame String)
-- Alternately, the main value can be a function from some input to a Scene that should be run:
-- For example, the main method of the overall program might be:
main : String -> Scene String
This avoids monadic FRP by requiring each scene to be a separate Elm program. It might be nice to construct multiple scenes in the same Elm file, but I don't see a good way to do it without radically changing how signals work.
Also, the top-level program only gains control between two scenes and they always take up the entire view. The effect is something like an operating system that doesn't support multi-tasking. This isn't so flexible, but if it's good enough for the iPhone, maybe it's not so bad?
- Brian