… Maybe I’m too Haskell brained to understand why this is a problem, haha. That looks fine? I don’t know Unison at all, bout you can probably elide the type annotation too?
Comment on Which programming language is hard to understand?
Pyroglyph@lemmy.world 1 year agoOh god, they say it’s a friendly language but their hello world is:
helloWorld : '{IO, Exception} () helloWorld _ = printLine "Hello World"
Chobbes@lemmy.world 1 year ago
Knusper@feddit.de 1 year ago
Well, it always depends, to whom it’s friendly.
I don’t think, it’s useful to hyper-optimize for Hello World, just so it looks simple (when it’s not).
Most learners will know what these syntax elements mean quite quickly. And from that point forward, they will find the language simpler, because there’s no special rules when precisely you’re allowed to leave out e.g. type annotations, even though any real program always wants to have them.
Pyroglyph@lemmy.world 1 year ago
helloWorld : '{IO, Exception} () helloWorld _ = printLine “Hello World”
I agree. I was more referring to the various symbols which don’t appear to have a clear purpose. They raise questions for me. Here are some of them:
helloWorld
there twice?’
for?()
for?_
?I’m aware that you can just look these things up, but there’s at least 4 mildly confusing things in something that is rather simple in every other language.
Take Rust for example. I’ve heard people say it’s complex, yet it’s printline still simple:
Coming at this with the same lens, the only mildly confusing thing is the
!
.I’m not saying “how Hello World is written is the be all and end all of language complexity”, but for a task that’s so simple in basically every other language to look like that in Unison, it just doesn’t fill me with confidence for the friendliness rest of the language.
Knusper@feddit.de 1 year ago
Ah, now you’re talking my language. 🙃
Well, for one you’re forgetting the main():
Then Rust already has syntactic sugar to omit the Unit-return-type, so it’s really:
And then Rust decided to make println!() blocking. It could also look like this:
async
is what the’
in Unison is. I guess, because it is so commonly used in Unison.And Rust decided, if the println!() fails, then panic!(). But I can see merit in a language that can guarantee that a given function cannot terminate your program. And that would mean we’d have to at least ignore the result in Rust:
And like, yeah, are you seeing the parallels? It’s a handful of small design decisions that make a huge difference here.
And you can absolutely argue that Rust took the less rigorous, less consistent approach for its println!().
I do think, that’s fine. Rust doesn’t give guarantees for not terminating to begin with and so, if println!() should ever not work, I do think, it’s fine to abort mission.
And the decision to not make println!() async doesn’t affect the remaining language design. Most production codebases will practically never use println!() anyways and should someone genuinely need an
async_println!()
, then that can be built.But yeah, personally, it does excite me to see that the Unison authors thought differently. Even if it’s just sheer curiosity what they do with it and whether that added consistency is nice to work with.
jadero@programming.dev 1 year ago
This is what attracted me. Before I sold out to VB and Access in the early 1990s, I was just a labourer and hobby programmer of the “language junkie” type. The same three programs written in every language I could find (Metaphone, Pong, and Rolodex).
Now I’m retired (but 10 years away from programming) and want to try to reboot that hobby. I thought I was just making a tiny little complaint about my aged brain, not opening up a whole thread!
otl@lemmy.sdf.org 1 year ago
You’ve done a great job of showing what it feels like when I see Rust sometimes. There’s something about the way that it “builds up” on the page over time… I’ve never written any Rust - I’ll get to it one day! - but I found this article interesting look at how and why design decisions effect the final syntax: matklad.github.io/2023/…/rusts-ugly-syntax.html
Crazazy@feddit.nl 1 year ago
Alright as someone who likes Haskell and has dabbled in unison before, I believe I can answer all these questions for you:
It is common in languages like haskell and ocaml to first mention the type of a function, so in this case:
helloWorld
is'{IO, Exception} ()
. That is it’s type signature (important for later)helloWorld
is\_ -> println "Hello, World!"
Here is where I have to get into the nitty gritty of how unison actually works. Unison has what programming language researchers call an effect system. The type signature of
helloWorld
indicates that it can perform theIO
andException
types of side effects, and these need to be handled. (in this case, they are handled by the compiler, but other types of side effects can be handled by the programmer themselves)However, for reasons Unison does not like dealing with eagerly evaluated non-function values with side effects. For this reason, there is
'
. Essentially, what it does is turn a value into a function that accepts()
as it’s argument. We could therefore say that the type signature ofhelloWorld
is also() -> {IO, Exception} ()
. The last()
indicates that, next to it’sIO
andException
side effects, it also returns()
as a value. This is because, in functional programming languages, all functions need to return values (or run infinitely, but that is for another topic)Now I’ve been used to functional programming for quite a while now, so things that seem natural to me can be absolutely woozy for anyone not used to this paradigm. So if anything still feels vague to you feel free to comment