Replies: 1 comment 3 replies
-
We won't be adding recursive let as you can use a top level function of the fix point combinator function to the same effect. |
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
In functional programming, auxiliary recursive functions are a common pattern I think (at least from my experience).
For instance in ocaml you can implement factorial as:
(I know that this is not the best factorial implementation, and that in this case the aux function can be considered and anti-pattern, but that is an other debate, and the example is simple).
This does not seem to be possible in gleam however as in gleam only module-level functions can be named:
And anonymous function handle (variable) won't be in scope of the said function
I tried to pass the function as a callback argument as a ungly workaround, but cannot be typed correctly I think (recursive types):
So I wonder:
rec
like keyword be envisageable in gleam ?rec
would allow something like:(or maybe rec would not even be needed ? That would be even cooler)
Thanks!
PS: On a personnal note, and It seems that this have been discussed in #346 and #349, but I think having some sort of let rec in, or another solution to make top level and nested function the same would be really nice. I've been loving gleam so far, but not having a single type of function (top level could be
let pub top_level_function = fn () {}
feels a bit weird to me. The ability to do the same things in or out of top level context would be awesome. Thanks again for the incredible work tho, gleam has been a joy :))Beta Was this translation helpful? Give feedback.
All reactions