Where for local functions

111 views
Skip to first unread message

Igor Bukanov

unread,
Jun 18, 2017, 6:00:42 AM6/18/17
to Elm Discuss
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.

Francesco Orsenigo

unread,
Jun 18, 2017, 10:57:51 AM6/18/17
to Elm Discuss
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.

Igor Bukanov

unread,
Jun 18, 2017, 11:41:34 AM6/18/17
to Elm Discuss
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.
Reply all
Reply to author
Forward
0 new messages