Discussion:
[elm-discuss] Where for local functions
Igor Bukanov
2017-06-18 10:00:42 UTC
Permalink
Hello,

past discussions about adding the where clause to Elm typically suggested to use it as syntax sugar for the let.

As far understand, this is how things are done in Haskell. Moreover, using the where is very natural there as syntax order follows the lazy evaluation strategy making it easier to reason about things.

This does not work for Elm as the language is strict. Yet strictness is only relevant for expressions, not function definitions. So perhaps restricting the where only for local function definitions similarly to Idris (strict language) may work for Elm?

Compare:

let triple x = x * x * x
in
List.map triple listOfInts

versus

List.map triple listOfInts
where
triple x = x * x * x

For me the let version looks uglier as the syntax order is reverse of the evaluation.

For this reason I have noticed that I do not like to move complex lambdas into local functions. Rather I wait until they become even more complex. Then I make them top-level functions defined *after* the function that uses them.
--
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.
Francesco Orsenigo
2017-06-18 14:57:51 UTC
Permalink
Hi Igor,

my understanding is that `where` has not been implemented and will not be
implemented to 1) keep the syntax lean and 2) ensure a consistent coding
style.
I don't think Elm should have a `where` clause.
Coming from Haskell and physics, I instinctively liked the `where` syntax
better, but as soon as I got some experience with Elm, using let..in became
natural.
More in general, in my experience this kind of aesthetic preference comes
largely from habit.
Post by Igor Bukanov
Hello,
past discussions about adding the where clause to Elm typically suggested
to use it as syntax sugar for the let.
As far understand, this is how things are done in Haskell. Moreover, using
the where is very natural there as syntax order follows the lazy evaluation
strategy making it easier to reason about things.
This does not work for Elm as the language is strict. Yet strictness is
only relevant for expressions, not function definitions. So perhaps
restricting the where only for local function definitions similarly to
Idris (strict language) may work for Elm?
let triple x = x * x * x
in
List.map triple listOfInts
versus
List.map triple listOfInts
where
triple x = x * x * x
For me the let version looks uglier as the syntax order is reverse of the evaluation.
For this reason I have noticed that I do not like to move complex lambdas
into local functions. Rather I wait until they become even more complex.
Then I make them top-level functions defined *after* the function that uses
them.
--
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.
Igor Bukanov
2017-06-18 15:41:34 UTC
Permalink
In Idris the let is used for local variables while the where is for local functions. This strikes me as a very nice solution for a functional strict language. It separates the strict expressions that must be calculated before the main expressions from function helpers that may or may not be called after the main expression has started. This way the source follows the evaluation order avoiding an awkward jumping of reasoning when both functions and variables are mixed in the let clause.
--
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.
Loading...