Hello! I guess this is mainly a question to @round patio about the design process of this feature. I'm doodling my own language idea and was wondering whether there would be downsides to not having something like use or y <- someMonad at all, and instead having them use-d automatically. When researching this, have you seen some examples of languages doing that? Do you have any thoughts on it?
#`use` syntax - alternatives
1 messages · Page 1 of 1 (latest)
What do you mean by used automatically?
More specifically I'm wondering about
myFn(): IO(Unit)
myFn() =
IO.println("hello")
x = 1
y = IO.ask("xyz: ")
IO.println("you said: $y")
being desugared to pure monadic form (not actual user-usable syntax, just for illustration):
IO.println("hello") >>= \() ->
let x = 1 in
IO.ask("xyz: ") >>= \y ->
IO.println("you said: $y")
ie. varName = expr can mean two different things
if monadic, it's expr >>= \varName ->, otherwise it's let varName = expr in
So you'd force every function to take a callback? Sounds like it would result in a lot of boilerplate code ?
Hm I don't think so, normal fns wouldn't take callback
You’re misunderstanding use, its not do notation
Yes, best not talk about monads and use together, they are unrelated
Apologies 😁
Is it that if the function accepts a function as the last argument and it is omitted then you would automatically use the rest of the body as the callback?
If so, I would prefer to have a syntax for it in order to make it more clear what is happening
For Gleam we always pick clarity over brevity
I think it comes down to what your language is like and what it is trying to do
I'm definitely leaning towards syntax sugar while staying pure functional. The original code snippet feels imperative, and I'm wondering whether it can be pulled off or whether it limits you somewhere later.
Actually on the Elm Slack somebody mentioned you might in some scenarios want to return the "wrapped" thing, not automatically unwrap it. 🤔
So, I'm searching for whether some language has tried this already. So far it seems everybody kept the "await" explicit