In my README, I've been writing down a few tips for converting from Elm to Purescript.
Lately, I've actually been converting a fair bit of Javascript as well (from the parts of Elm implemented in Javascript). So, I should really start documenting some tips for doing that.
For instance, I have a few ideas about dealing with mutability, and could give some examples. E.g., I'd approach the possibilities in about this order (from most attractive to least attractive):
See if you can trivially rewrite without mutability ... often possible.
See if you can use a fold of some kind to keep some state updated.
Consider using recursion ... sometimes you can recurse in situations that you might otherwise mutate.
If the mutation is purely local (i.e. you mutate, but don't need to keep the mutated state), then consider runST, newSTRef etc.
If the mutation occurs across multiple functions, but the mutation takes place inside a larger operation using those functions that doesn't escape, consider using StateT etc. Talk about how this is sort of similar to generating and using closures.
If the mutation is truly chaotic, and references need to be passed around like spaghetti, then try newRef etc.
There are things that could also probably be said about converting object-oriented Javascript code to Purescript.
In my README, I've been writing down a few tips for converting from Elm to Purescript.
Lately, I've actually been converting a fair bit of Javascript as well (from the parts of Elm implemented in Javascript). So, I should really start documenting some tips for doing that.
For instance, I have a few ideas about dealing with mutability, and could give some examples. E.g., I'd approach the possibilities in about this order (from most attractive to least attractive):
fold
of some kind to keep some state updated.runST
,newSTRef
etc.StateT
etc. Talk about how this is sort of similar to generating and using closures.newRef
etc.There are things that could also probably be said about converting object-oriented Javascript code to Purescript.