Continued from https://github.com/elm-lang/elm-compiler/issues/621.
--
You received this message because you are subscribed to the Google Groups "Elm Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elm-discuss...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Continued from https://github.com/elm-lang/elm-compiler/issues/621.
--
You received this message because you are subscribed to the Google Groups "Elm Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elm-discuss+unsubscribe@googlegroups.com.
we have legitimate issues with "let".
--
Please no. Not every Haskell feature should have a place in elm, especially if there is already a construct that works (and overlaps 100%?)Please do not make elm2016, elm2017 or coffeeElm, with all kinds of syntactic sugar because some user from another language still thinks this way.
That being said I favour the simplicity of a single form, I just wish where had been chosen instead of let/in. The argument regarding being able to use let/in with anonymous functions seems irrelevant as it's use would be a clear sign that the function should be broken out into a named function.
Let/in leads to a sort of vertigal zig zagging as you need to jump to the bottom then scan backwards for the supporting information.
The pattern Joey suggests seems good, the counter argument though is that you need to check the 'in' to know if that pattern is being used so you end up doing the zig zag read anyway.
The argument regarding being able to use let/in with anonymous functions seems irrelevant as it's use would be a clear sign that the function should be broken out into a named function.
Those in favor of where clauses, would you mind summarizing any arguments from the thread that do not rely on personal preference but concrete improvements to code readability or maintainability, in a way not achieved by Joey's suggestion? We are looking for code examples in which where-clauses either let you do something let-clauses don't, or are visibly superior to them.
List.indexedMap (\i x -> let bar = f x.foo in g i bar) aList
foo : (List A, Int)
foo = (my ++ intent, goes - here)
where my = ...
intent = ...
goes = ...
here = ...
foo : (List A, Int)
foo = (my ++ intent, goes - here)
where ...
foo : (List A, Int)
foo =
let my = ...
intent = ...
goes = ...
here = ...
in (my ++ intent, goes - here)
-- | Haskell
bar :: [a] -> b
bar = foldl f someAccVal
where f acc x = ... -- complicated lambda
let
ret = some_expresssion_with_p1_to_pk
p1 = e1
...
pk = ek
in
retfoo.bar
.bar foo
let x = a in b
(\x -> b) a
--
You received this message because you are subscribed to the Google Groups "Elm Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elm-discuss...@googlegroups.com.
I don’t think it is possible to first decide about where and then “whether let will be dropped”. I am fine with adding where. I am absolutely against dropping let. So if first where is added, and only then the argument “but we must not have two ways of doing almost the same thing” kicks in, then you will want to discuss about dropping let, whereas I will start arguing that if one must be dropped, then where is the one. :-)
If I am not alone in this, then it is counterproductive to not up front discuss the actual alternatives “only let“, “only where“, “where and let“.
And I don’t think that lambda + let was refuted. It is fine to encourage as a style guide that anonymous functions best do not have local bindings inside. It is a different matter altogether to actually outlaw those two to ever be used together. It seriously hampers the use/combination of functional features. My comment in the earlier discussion that was mainly on this point was this. That was written a long time ago, I don’t have the details of the code present in mind anymore, so I can’t tell whether I feel 100% like I did back then on that particular example. But I can suggest this:
Make an experiment asking experienced Haskell programmers what they would chose if they had to give up one of where and let from their language. I bet that (being aware giving up let would mean they can’t have local definitions inside a lambda-expression anymore), the majority would chose to give up where.
In case you want to start counting: Here is one experienced Haskell programmer who would chose to give up where in that case. (I have been programming Haskell for 20 years next summer.)
lambda + let was refuted. I am not myself convinced that “there must only be one way” is always a useful philosophy. But I don’t get to decide about when it is followed in the Elm design. The reality may simply be that there is no way to get both let and where into Elm, that’s why I thought it “dangerous” to consider where as an isolated matter, as if adding it without removing let was even an option. (I can’t say whether it is an option.)
About this:
Can I trust that the results will be respected, at least within the scope of this debate?
I can only speak for myself. Of course, having proposed the experiment, I will not anymore claim that a majority of experienced Haskell programmers would prefer abandoning where over abandoning let if the data says otherwise. Whether that “admission” of mine would buy you anything in this debate is another matter. I don’t speak for anyone than myself here anyway. And it’s not like it is exactly my opinion that keeps you from getting where in Elm. :-)
--
You received this message because you are subscribed to the Google Groups "Elm Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elm-discuss+unsubscribe@googlegroups.com.
Ah, actually one more thought, I don’t remember whether it was considered in the original discussion:
The situation of where vs. let is a bit different in Elm than in Haskell via the point that Elm does not allow multiple equations for a function. Concretely, in Haskell one can have:
f (Leaf x) = some expression
where ... some local definitions involving x ...
f (Node s t) = some other expresion
where ... some local definitions involving s and t ...
That’s easy to translate into an Elm form
f tree =
case tree of
Leaf x -> ...
Node s t -> ...
if one may use let-bindings in the branches.
But if Elm only had where, and it would work like in Haskell, what would you do? Because the following is not legal in Haskell:
f tree =
case tree of
Leaf x -> some expression
where ... some local definitions involving x ...
Node s t -> some other expression
where ... some local definitions involving s and t ...
--
zing :: Num t => [t] -> t
zing list = case list of
[] -> a
where a = 1
a:as -> b
where b = a + 1Janis, the following compiles for me: …
Right, where does not work for expressions, but for right-hand sides, of which pattern match branches are an instance.
The next question would be, still under the assumption that a choice has to be made between where and let because both won’t be made available at the same time, how well “where-only” would work if in addition one wants to have a local binding that spans all pattern match branches, i.e., something one would currently write in Elm like so:
f tree =
let
a = ... something ...
in
case tree of
Leaf x -> let b = ... in ... using a and b ...
Node s t -> let c = ... in ... using a and c ...
--
You received this message because you are subscribed to the Google Groups "Elm Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elm-discuss...@googlegroups.com.
It’s how they are implemented in Haskell, and people asking for where in Elm typically do so by saying “we want where like in Haskell”. One could probably come up with new parsing rules that allow where to be used anywhere in an expression, thus also for example for local bindings inside a lambda-abstraction. But that would require new design work to make sure everything fits together and the syntax remains unambigous and usable. That probably presents an even bigger hurdle for acceptance into Elm than “just” wanting to get Haskell-style where in.
To unsubscribe from this group and stop receiving emails from it, send an email to elm-discuss+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "Elm Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elm-discuss+unsubscribe@googlegroups.com.
f tree = work
where a = ...
work = case tree of
Leaf x -> -- using a and b
where b = ...
Node s t -> -- using a c
where c = ...--
You received this message because you are subscribed to the Google Groups "Elm Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elm-discuss...@googlegroups.com.
f tree =
case tree of
Leaf x ->
munge a b
where
b = ...
Node s t ->
munge a c
where
c = ...
where
a = ...
Yes, and there is no need to only imagine it, since that already is a legal use of Haskell-style where. But I have doubts about its readability, with the adjacent where lines towards the bottom, where only indentation determines what the scope of the respective definitions is. And since Colin probably knows that that way of writing the example would have been legal as well, his giving another version with where instead may indicate he also considers these “adjacent wheres” undesirable in terms of clarity/readability of the code.
In any case, even just the fact that let (with in) is a two-keywords-construct makes it clearer for nested uses.
To unsubscribe from this group and stop receiving emails from it, send an email to elm-discuss+unsubscribe@googlegroups.com.
f tree =
case tree of
Leaf x -> munge a (b x)
Node s t -> munge a (c s t)
where
a = ...
b x = ...
c s t = ...This comes off as an attempt to end the discussion before it begins. Unless you know something we don't?
Will Evan never consider improvements to syntax?
Will he refuse to read this thread?
Is he the kind of person who is adverse to criticism in general?
I've never met him personally, but I'm sure he's very well-intentioned.
That said, conflict breeds evolution and improvement.
Elm needs people to tell it that it isn't good enough, and that's what I and the flood of past and future people wanting `where` in Elm are saying.
On `where`<Snip>
Kinda like how you currently have the freedom to chose between |> and <|, >> and <<
--
You received this message because you are subscribed to the Google Groups "Elm Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elm-discuss+unsubscribe@googlegroups.com.
--
You received this message because you are subscribed to the Google Groups "Elm Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elm-discuss...@googlegroups.com.