Stream: ideas

Topic: type annotations without duplication


view this post on Zulip itmuckel (Mar 17 2023 at 22:25):

Hi! I've wondered since first time seeing haskell code:

fullName : Str, Str -> Str
fullName = \firstName, lastName ->
    "\(firstName) \(lastName)"

Why is it necessary for the function name to be repeated? Couldn't _ : Str, Str -> Str work as well? Or are there advantages to doing it like this?

view this post on Zulip itmuckel (Mar 17 2023 at 22:25):

Of course it wouldn't align the : with the = :tear:

view this post on Zulip Brendan Hansknecht (Mar 17 2023 at 22:31):

I think it is just a design and readability thing. Also, your alternative syntax is missing the variables for the arguments. It just has their type.

view this post on Zulip Brendan Hansknecht (Mar 17 2023 at 22:32):

But could be something like:
foo = firstName: Str, lastName: Str ->

view this post on Zulip Brendan Hansknecht (Mar 17 2023 at 22:32):

Though that is missing the return type also.

view this post on Zulip Brendan Hansknecht (Mar 17 2023 at 22:33):

Oh, you just meant unnamed on the line before.

view this post on Zulip Brendan Hansknecht (Mar 17 2023 at 22:34):

_ : Str, Str -> Str
fullName = \firstName, lastName ->
    ...

view this post on Zulip Brendan Hansknecht (Mar 17 2023 at 22:35):

That could parse too.

view this post on Zulip Brendan Hansknecht (Mar 17 2023 at 22:36):

I think it also falls under my first comment. Just design and readability and such. Alternatives definitely could be made.

view this post on Zulip Martin Stewart (Mar 17 2023 at 22:45):

Doesn't Roc let you just write fullName : Str, Str -> Strwhich it treats as a

fullName : Str, Str -> Str
fullName = \_, _ -> panic

?

If it does then using _ instead of the fullName wouldn't work.

view this post on Zulip Brendan Hansknecht (Mar 17 2023 at 22:53):

Sure sure, but i don't think the specific character there matters, more the general idea of not repeating the name twice.

view this post on Zulip Zeljko Nesic (Mar 18 2023 at 01:36):

if you ask me even this might be legit

fullName : Str, Str -> Str
= \firstname, lastname -> "\(firstname) \(lastname)"

view this post on Zulip Georges Boris (Mar 18 2023 at 01:41):

Str, Str -> Str
fullName = \firstname, lastname -> "\(firstname) \(lastname)"

gg

view this post on Zulip Anton (Mar 18 2023 at 08:51):

I think the alignment of the existing design is really good, it's nice to have the columns of the first type and first argument name close together.

fullName : Str, Str -> Str
fullName = \firstName, lastName ->

Although my preferred way to display it in the editor would be something like this:

            Str        Str      -> Str
fullName = \firstName, lastName ->

Last updated: Jun 16 2026 at 16:19 UTC