Lately I’m thinking a lot about Mutability. Mutability in Elm. Is that even possible?
Here is how I imagine that mutability could work in Elm. This is just a suggestion, I’m not expecting that this would actually be implemented in Elm. It’s just a thought experiment.
My Idea would be to have a Adress
type that can be thought of as a variable in the JavaScript world. Here is some made up code to showcase how I imagine this adress type would behave:
{-| Swapping the values of two adresses
let temp = b;
b = a;
a = temp
-}
swap : Adress Int -> Adress Int -> Task Error ()
swap a b =
(Adress.get b) --Task Error Int
|> Task.andThen (\intB ->
Task.sequence
[ b |> Adress.equals a --Task Error ()
, a |> Adress.set intB --Task Error ()
]
|> Task.map (always () )
)
What do you think? Is that something that might be worth investigating? I’m not sure how this might be implemented though. I don’t want to suggest adding a new Type to elm/core, before I haven’t explored all other options. Can this be done using Ports or using custom elements?
Now that elm-conf is cancelled I would like to use that free time to investigate into this topic. So if anyone is interested, I’d love to collab.