Stream: ideas

Topic: static dispatch - on Str


view this post on Zulip Luke Boswell (Jan 23 2025 at 23:25):

Instead of the pipe here...

"Default color" |> ANSI.color({ fg: Default, bg: Default })

will we be able to dispatch on a Str?

"Default color".color({ fg: Default, bg: Default })

view this post on Zulip Luke Boswell (Jan 23 2025 at 23:27):

Thinking about this more... it's not a sensible question. Str isn't going to be a Custom Type.

view this post on Zulip Luke Boswell (Jan 23 2025 at 23:29):

I'm just looking at my ANSI examples... and debating if I refactor these to remove the |>

ANSI.color("Default color", { fg: Default, bg: Default })

view this post on Zulip Luke Boswell (Jan 23 2025 at 23:31):

Thinking about this more... I would probably refactor the API to have a ANSI.styled : Str -> ANSI or similar and then have methods hanging off that to style the string segment. Sounds like a job for future Luke. :smiley:

view this post on Zulip Sam Mohr (Jan 23 2025 at 23:42):

I think Str will be a custom type

view this post on Zulip Sam Mohr (Jan 23 2025 at 23:42):

And that you can call methods on a string

view this post on Zulip Sam Mohr (Jan 23 2025 at 23:42):

In the same way List would work

view this post on Zulip Sam Mohr (Jan 23 2025 at 23:43):

We need methods like List.map to work

view this post on Zulip Luke Boswell (Jan 23 2025 at 23:43):

Wait so "str".color(...) might work? I won't be able to write my own methods because Str is a builtin.

view this post on Zulip Sam Mohr (Jan 23 2025 at 23:45):

That would be my expectation yes

view this post on Zulip Richard Feldman (Jan 23 2025 at 23:45):

no, that would not work

view this post on Zulip Sam Mohr (Jan 23 2025 at 23:45):

In general, methods only get defined in the module of the custom type

view this post on Zulip Richard Feldman (Jan 23 2025 at 23:45):

right

view this post on Zulip Richard Feldman (Jan 23 2025 at 23:45):

because literally what the . is doing there is saying "go look up the type of the thing before the . and call a function by this name in its module"

view this post on Zulip Sam Mohr (Jan 23 2025 at 23:45):

If we didn't require that, then we'd have to do some expensive Rust style trait resolution

view this post on Zulip Richard Feldman (Jan 23 2025 at 23:46):

so "str".color(...) does exactly the same thing as Str.color("str", ...)

view this post on Zulip Brendan Hansknecht (Jan 24 2025 at 02:34):

That said, assuming we support .(fn) you would be able to do:

from ANSI import color

"Default color".(color)({ fg: Default, bg: Default })

view this post on Zulip Brendan Hansknecht (Jan 24 2025 at 02:35):

This is part of the reason I really want to support .(fn)(...)

view this post on Zulip Anthony Bullard (Jan 24 2025 at 03:04):

Just without the python import syntax @Brendan Hansknecht :wink:

view this post on Zulip Sam Mohr (Jan 24 2025 at 03:05):

We need a Zulip LSP!!!

view this post on Zulip Anthony Bullard (Jan 24 2025 at 03:05):

First we need Zulip to support Roc syntax highlighting

view this post on Zulip Anthony Bullard (Jan 24 2025 at 03:05):

I wish we had a way to patch that in

view this post on Zulip Anthony Bullard (Jan 24 2025 at 03:05):

Even if it was just TextMate grammar

view this post on Zulip Sam Mohr (Jan 24 2025 at 03:06):

Someone was working on it a while back

view this post on Zulip Luke Boswell (Jan 24 2025 at 03:10):

@Isaac Van Doren I think

view this post on Zulip Anthony Bullard (Jan 24 2025 at 03:14):

I know that @Eli Dowling owns the Treesitter grammar, right?

view this post on Zulip Sam Mohr (Jan 24 2025 at 03:14):

Yep, but it's not Treesitter

view this post on Zulip Anthony Bullard (Jan 24 2025 at 03:14):

Right, I know

view this post on Zulip Anthony Bullard (Jan 24 2025 at 03:14):

And the TS grammar is woefully out of date now I think

view this post on Zulip Sam Mohr (Jan 24 2025 at 03:14):

https://docs.zulip.com/help/code-blocks#language-tagging

view this post on Zulip Luke Boswell (Jan 24 2025 at 03:15):

I think Eli is travelling for a month or so, he said he'd pickup the grammar one syntax madness settles a little

view this post on Zulip Sam Mohr (Jan 24 2025 at 03:15):

#contributing > Pygments @ 💬

view this post on Zulip Isaac Van Doren (Jan 24 2025 at 03:17):

I did highlight-js support for roc but have not done textmate

view this post on Zulip Brendan Hansknecht (Jan 24 2025 at 03:22):

Anthony Bullard said:

Just without the python import syntax Brendan Hansknecht :wink:

I have been writing too much python at work

view this post on Zulip Sam Mohr (Jan 24 2025 at 03:24):

You mean any at all?/s

view this post on Zulip Sam Mohr (Jan 24 2025 at 03:26):

Small Python Good, Big Python Bad

view this post on Zulip Brendan Hansknecht (Jan 24 2025 at 03:28):

Indeed.


Last updated: Jun 16 2026 at 16:19 UTC