this post was submitted on 16 Dec 2023
67 points (85.3% liked)

Programming

17313 readers
195 users here now

Welcome to the main community in programming.dev! Feel free to post anything relating to programming here!

Cross posting is strongly encouraged in the instance. If you feel your post or another person's post makes sense in another community cross post into it.

Hope you enjoy the instance!

Rules

Rules

  • Follow the programming.dev instance rules
  • Keep content related to programming in some way
  • If you're posting long videos try to add in some form of tldr for those who don't want to watch videos

Wormhole

Follow the wormhole through a path of communities [email protected]



founded 2 years ago
MODERATORS
 

A friendly programming language from the future.

you are viewing a single comment's thread
view the rest of the comments
[–] [email protected] 33 points 11 months ago* (last edited 11 months ago) (2 children)

Literally the opposite of friendly. Already in the hello world you have two imports for extremely basic functionality (why should I have to import the ability to throw exceptions??) and a completely enigmatic symbol ' that apparently has a significant function.

A "friendly" programming language should be readable without knowing esoteric symbols.

Really got my hopes up with that headline that it'd be a python-level intuitive-to-read language with static typing.

[–] [email protected] 9 points 11 months ago (2 children)

What you expected sounds more like what nim offers.

[–] zarlin 5 points 11 months ago

python-level intuitive-to-read language with static typing

Agreed, this is exactly Nim

[–] [email protected] 1 points 11 months ago

Thanks I'll check it out

[–] [email protected] 8 points 11 months ago (1 children)

There are no imports, these are type annotations

[–] [email protected] -4 points 11 months ago (3 children)

Do I really have to declare that something requires exceptions?

[–] [email protected] 8 points 11 months ago (1 children)

Yes, in functional programming you want to use pure functions. Exceptions are impure, therefore it has to be declared.

Other functional languages don't even have exceptions

[–] [email protected] 1 points 11 months ago (1 children)

I'm surprised about this statement, I would have said that exceptions are the consequence of an impure operation (that may or may not fail differently every time you call it).

[–] [email protected] 1 points 11 months ago (1 children)

I'm currently learning functional languages and have only limited knowledge, but from what I've read now you are right. Throwing exceptions is pure, but catching them is impure.

In this case I guess the printLine function can throw an exception therefore the calling function must be declared with Exception?

[–] [email protected] 2 points 11 months ago (2 children)

I would even have said that both throwing and catching should be pure, just like returning an error value/handling should be pure, but the reason for the throw/returning error itself is impure. Like if you throw and ioerror it's only after doing the impure io call, and the rest of the error reporting/handling itself can be pure.

[–] Pipoca 1 points 11 months ago

Pure functions should be referentially transparent; you should be able to replace them with whatever value they evaluate to without changing the semantics of your code.

Throwing is referentially impure: what value do you get from calling x => throw new RuntimeException()?

Instead, functional languages prefer to return a tagged union of the value or the error.

[–] [email protected] 1 points 11 months ago

Sounds good,

but would the preferred way be to use a wrapper type, which holds either the data or the error and avoid exceptions completely?

[–] Pipoca 1 points 11 months ago* (last edited 11 months ago)

Functional languages typically have type inference, so the type signatures are entirely optional. I haven't looked that deeply at unison, but I'd be entirely unsurprised if it had global type inference and if all or most type signatures were optimal.

It's less that you have to declare something can do IO or throw an exception, and more that you're calling something from the standard library that does IO or throws an exception.

Most stuff does neither. There's a type level distinction between normal, regular pure code, and impure effectful code, so it's easy to tell from the type signature whether a function is pure or not.

[–] [email protected] 1 points 11 months ago

That's one of the things I appreciate in a language/framework. Drives me nuts getting an exception from a dependency of a dependency of a dependency.

Even better if its baked into the type system and I can't run my code without handling it.