Coming soon - Get a detailed view of why an account is flagged as spam!
view details

This post has been de-listed

It is no longer included in search results and normal feeds (front page, hot posts, subreddit posts, etc). It remains visible only via the author's post history.

4
Working With Messages That Only Arise In Certain States
Post Body

Hi there. I'm currently building a board game (backgammon) with ocaml-vdom, an OCaml implementation of the Elm architecture. Because that's still a very small project, I'm hoping my question might translate here.

I'm trying to figure out how my update function should look when when working with messages that only arise in a given state of the app. For example, say the possible states include:

  1. Before the game, when users are still choosing which color to play as
  2. During the game
  3. After the game, when somebody has won

During the game, one message that can arise looks something like Move (source, destination). In states (1) and (3), however, this message should never arise, nor is there any meaningful update that could be applied. So I end up having to write boilerplate where I do nothing (or assert false) if the message is sent in one of these states.

Is there a standard/idiomatic way of handling this type of situation? I'm having trouble even figuring out how I could Google it. One thing that looks possibly applicable is the tutorial section on composing, where I could break up messages into a sum type of BeforeGameMessage, GameMessage, etc. But I wanted to make sure I'm on the right track, since this is unfamiliar territory for me.

Any help is appreciated, and thanks in advance.

Author
Account Strength
90%
Account Age
7 years
Verified Email
Yes
Verified Flair
No
Total Karma
1,051
Link Karma
49
Comment Karma
912
Profile updated: 2 days ago
Posts updated: 7 months ago

Subreddit

Post Details

We try to extract some basic information from the post title. This is not always successful or accurate, please use your best judgement and compare these values to the post title and body for confirmation.
Posted
6 years ago