Alright as someone who likes Haskell and has dabbled in unison before, I believe I can answer all these questions for you:
Why is helloWorld there twice?
It is common in languages like haskell and ocaml to first mention the type of a function, so in this case:
the type of helloWorld is '{IO, Exception} (). That is it’s type signature (important for later)
the implementation of helloWorld is \_ -> println"Hello, World!"
What’s the ' for?
What are the () for?
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 the IO and Exception 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 of helloWorld is also () -> {IO, Exception} (). The last () indicates that, next to it’s IO and Exception 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
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