jonascarpay / apecs

a fast, extensible, type driven Haskell ECS framework for games
392 stars 43 forks source link

Argument order in Reacts.react #108

Open dpwiz opened 1 year ago

dpwiz commented 1 year ago

Currently it is:

react entity old new token = ...

I propose moving the old and new to the end, so they could be matched more easily by \cases in 9.4:

react _entity token = \cases
  Nothing (Just new) -> created token
  (Just old) (Just new) -> updated token
  (Just old) Nothing -> deleted token
  Nothing Nothing -> pure () -- idk when this happens
dpwiz commented 1 year ago

:thinking: OTOH, the token may be in the right place if it actually used:

  react entity old = \case
    Just new -> insert new
    Nothing -> \token -> delete entity token
jonascarpay commented 1 year ago

I think I'm in favor of this. Although if we do, maybe it's actually better to just have a single data type so you can just use a single \case?

data Update a
  = Insert a
  | Delete a
  | Update a a -- Not necessarily implies a /= a!

Nothing Nothing -> pure () -- idk when this happens

So, this just happens when you call delete on something that was never there. How often that happens is up to the user, I suppose. I'm not sure if it deserves a case in Update.

Also, I'll have to see if I can take some time to improve the Reactive haddocks, I forgot they were this terrible. I think the idea is super useful, I'd like it to be easier to use. I also think it could be moved from .Experimental.