jaredly / gravitron

a little game
https://gravitron.jaredforsyth.com
490 stars 19 forks source link

A few questions. #5

Closed quicksnap closed 6 years ago

quicksnap commented 6 years ago

Hello! I was looking through the code to refresh myself on Reason, and had a couple questions on your code:

1) Why did you chose to use polymorphic variants here? https://github.com/jaredly/gravitron/blob/master/src/Main.re#L90-L121

2) screenable is a GADT, right? I see that it's being used as a kind of container, and its constructor values are being pulled out in other places in the code. Why use a GADT instead of a record or something? https://github.com/jaredly/gravitron/blob/master/src/ScreenManager.re#L17-L18

Thanks for your time if you're able to help =) Just curious..

jaredly commented 6 years ago
  1. I used a polymorphic variant because I didn't have to have to worry about scoping, and making sure each screen function had access to the variant constructors.
  2. using a GADT for screenable allows it to "hide" a type within itself. Note how the Screen constructor mentions the 'state variable, but type screenable('context, 'transition, 'wrappedState) doesn't mention 'state. This means that you can have a list of screenables, where each one has a different 'state type, which is critical for my screen management to work.
quicksnap commented 6 years ago

Thanks for the info! I can grok most of the code now =)