Syntax Request: defining named values in current block #180
Replies: 9 comments
-
Yes this is something Elm has but Mint doesn't but the same thing can be achieved with a This is how I would structure it (might not be correct):
I find myself using this a lot where I need some temporary variables, and I don't really use I'm not opposed having a different language feature for this but it would make the language more complex. |
Beta Was this translation helpful? Give feedback.
-
Thanks!
|
Beta Was this translation helpful? Give feedback.
-
Hi! 👋 I'm excited for Mint because Elm is GTBAE. Thanks for all of your work on it.
I haven't spent a lot of time with Mint yet, so I may be confused, but this really threw me. Having to declare variables after they're used in the function body is confusing imo. I agree that having a |
Beta Was this translation helpful? Give feedback.
-
Thanks 🙂 Wasn't familiar with GTBAE had to look it up 😄 I've been thinking about this for some time now and this is what I came up with: Having only one construct would be easier to understand for newcomers, also implementation wise What do you think? |
Beta Was this translation helpful? Give feedback.
-
My meager understanding of Mint suggests that that would be useful (assuming that the standalone Would |
Beta Was this translation helpful? Give feedback.
-
Yes and |
Beta Was this translation helpful? Give feedback.
-
@gdotdesign I've wrote a lot of Mint code since then and I've found myself to having multiple nested So, to summarize: I would expect to declare variables directly in the function body, To see an example of too much indentation because of |
Beta Was this translation helpful? Give feedback.
-
I feel the same sometimes, I think its worth exploring, though it might not be possible since everything returns a single expression.
I'm assuming that you have the same code in Elm, did you have the same issue there as well?
I don't understand this, you don't need to declare a variable to use
|
Beta Was this translation helpful? Give feedback.
-
This is now possible since 0.17.0, so I'm closing this. |
Beta Was this translation helpful? Give feedback.
-
In Mint we cannot define named values besides of
where
,sequence
,parallel
ortry
blocks. It's not practical to usesequence
since it makes a different return type, aPromise
.Example
I have the following Elm code:
In Mint, the only place where one can define values such as
dir1
,dir2
,sizes1
orsizes2
is in thewhere
block AFTER function definition. However, it is not possible to do it after any case in acase
block.By rewriting from Elm to Mint, this is as far as I went to:
The first bad is the lack of array destructuring but it's covered in this issue: #177
The second is lack of local recursion: #179
But the main point here is that one cannot define values in block that would use them. Even a workaround does not seem to exist since nested
where
blocks does not seem to compile. And even if it would work then values may not be closured, I suppose.Benefits from having named values would be:
I have no proposal for a syntax yet, though.
Beta Was this translation helpful? Give feedback.
All reactions