Stream: beginners

Topic: Structural polymorphism and autocomplete


view this post on Zulip Alex Ott (Nov 24 2025 at 22:04):

I'm coming from this video https://youtube.com/watch?v=VnPw9rk8FI8 where Richard talk about structural polymorphism and compares it to rust/Haskel style "classification based polymorphism". From what I understood, you just write Roc functions and the type system figures out the correct set of constraints to put on the arguments of the function. Without knowing the types / interfaces beforehand, how does an LSP figure out the type of something before you write the function? If I ask for a list of methods available on some variable, where do they come from?

view this post on Zulip Richard Feldman (Nov 24 2025 at 22:29):

ah, so the type checker does know what they all are! So let's say I define a new custom collection type and I give it associated functions of .len() and .concat(other)

view this post on Zulip Richard Feldman (Nov 24 2025 at 22:31):

as soon as LSP asks "what methods are available after this dot?" the type checker can tell the LSP of the type of the thing before the dot by looking it up in scope, and once you know the type you can just ask directly what methods were explicitly defined on that type

view this post on Zulip Richard Feldman (Nov 24 2025 at 22:32):

so that part of it is no different from, say, defining a method on a class and the LSP looking up the class of the thing in front of the dot

view this post on Zulip Richard Feldman (Nov 24 2025 at 22:32):

now if I'm doing this on a type that's not concrete, then it all depends on what constraints I've specified for it

view this post on Zulip Richard Feldman (Nov 24 2025 at 22:36):

for example if I'm writing a function and I put a type annotation on it that says the function's your is val -> U64 where [val.len : val -> U64, val.reverse : val -> val] then the LSP would autocomplete a dot after its argument to have the two methods of len and reverse because those are the 2 methods I said in the annotation it was required to have

view this post on Zulip Alex Ott (Nov 24 2025 at 22:36):

So do you make those new custom collection types ad-hoc? or in the function signature themselves?

view this post on Zulip Alex Ott (Nov 24 2025 at 22:37):

You need to know, before writing the function, that val needs to have the len and reverse methods, right?

view this post on Zulip Richard Feldman (Nov 24 2025 at 22:37):

either in the function signature or if you like you can make a named thing to reuse (like a type alias) if there are common ones you don't want to write over and over

view this post on Zulip Richard Feldman (Nov 24 2025 at 22:37):

no, not necessarily

view this post on Zulip Richard Feldman (Nov 24 2025 at 22:38):

for example if you'd already written arg.len() somewhere else in the function then the type checker would infer the len constraint for you, based on how you used that len method call

view this post on Zulip Richard Feldman (Nov 24 2025 at 22:39):

obviously it can't read your mind, so if you're writing the function completely from scratch it won't infer any constraints :smile:

view this post on Zulip Alex Ott (Nov 24 2025 at 22:40):

I guess my underlying question is how do you plan on users of libraries to do "function / api surface discovery" I often find myself looking through the autocomplete methods looking for something that I want.

view this post on Zulip Richard Feldman (Nov 24 2025 at 22:40):

I think it will feel exactly like a normal language when it comes to autocomplete haha

view this post on Zulip Alex Ott (Nov 24 2025 at 22:41):

Ok.

view this post on Zulip Alex Ott (Nov 24 2025 at 22:43):

Also, a bit off topic from this question, but what other syntax did you explore before landing on the -> operator?

view this post on Zulip Alex Ott (Nov 24 2025 at 22:49):

Why not just use .?

view this post on Zulip Luke Boswell (Nov 24 2025 at 22:53):

. is already used for chaining methods (functions associated with the type), the -> operator is to call a function defined locally

view this post on Zulip Luke Boswell (Nov 24 2025 at 22:54):

we talked about many different operators in zulip -- over various different threads. I feel like we threw around every possible symbol

view this post on Zulip Alex Ott (Nov 24 2025 at 22:57):

Bringing up the autocomplete example again, do you plan on separating the lists of available functions/methods if I do x. vs x->? Or will the lists be combined and then the lsp replaces the . with a -> (or vice versa) if I selected a function when I had x.

view this post on Zulip Luke Boswell (Nov 24 2025 at 22:57):

I think this is the thread (it's very long) #ideas > static dispatch - pass_to alternative @ 💬

view this post on Zulip Alex Ott (Nov 24 2025 at 22:58):

Sorry, I wasn't able to find the threads. I'm new to zulip and searched for "->" but nothing came up

view this post on Zulip Alex Ott (Nov 24 2025 at 22:58):

I'll look harder!

view this post on Zulip Richard Feldman (Nov 24 2025 at 22:58):

by default I assume we'll start with just . autocomplete and then see if in practice there's demand for ->

view this post on Zulip Luke Boswell (Nov 24 2025 at 22:59):

Luke Boswell said:

I think this is the thread (it's very long) #ideas > static dispatch - pass_to alternative @ 💬

@Alex Ott can you see this thread?

view this post on Zulip Luke Boswell (Nov 24 2025 at 22:59):

I'm not sure if zulip let's you go back in time to older threads

view this post on Zulip Alex Ott (Nov 24 2025 at 23:03):

Yes I can


Last updated: Nov 28 2025 at 12:16 UTC