Stream: beginners

Topic: Type introspection


view this post on Zulip jan kili (Jan 02 2022 at 20:49):

Hey, is it possible to write one function that accepts either a Str or a Num and does different things to them... without requiring tag prefixing?

view this post on Zulip Brendan Hansknecht (Jan 02 2022 at 20:51):

No

view this post on Zulip Brendan Hansknecht (Jan 02 2022 at 20:51):

Would need a tag

view this post on Zulip jan kili (Jan 02 2022 at 20:51):

Hmmm darn

view this post on Zulip Brendan Hansknecht (Jan 02 2022 at 20:52):

At least i can't think of a way.

view this post on Zulip Brendan Hansknecht (Jan 02 2022 at 20:52):

Wouldn't expect a way to exist

view this post on Zulip Brendan Hansknecht (Jan 02 2022 at 20:52):

What are you trying to do?

view this post on Zulip jan kili (Jan 02 2022 at 20:52):

I'm trying to write a pretty printing library that can accept arbitrary data and converts it to a Str, similar to JS's JSON.stringify

view this post on Zulip jan kili (Jan 02 2022 at 20:53):

It works for Str and Num if the user provides a prefix tag to indicate which it is

view this post on Zulip jan kili (Jan 02 2022 at 20:54):

But as soon as you want to stringify a List of strings or numbers... or a Record of anything... The user would have to describe the entire type structure... Which defeats the purpose of a lightweight pretty printer

view this post on Zulip jan kili (Jan 02 2022 at 20:55):

Is a generic Roc pretty printer impossible?

view this post on Zulip Zeljko Nesic (Jan 02 2022 at 21:57):

Yes, trough abilities, aka simplified type classes aka better than interfaces :)

view this post on Zulip Zeljko Nesic (Jan 02 2022 at 21:57):

But they are not implemented yet

view this post on Zulip jan kili (Jan 02 2022 at 23:48):

Could I please see the design doc for abilities? For both library planning and excited curiosity :)

view this post on Zulip Zeljko Nesic (Jan 03 2022 at 00:02):

This was Richard's document, for sure we should organize this knowledge better, but it's still open issue so no sweat.

https://docs.google.com/document/d/1kUh53p1Du3fWP_jZp-sdqwb5C9DuS43YJwXHg1NzETY/edit

view this post on Zulip Zeljko Nesic (Jan 03 2022 at 00:02):

This is conversation thread about them:
https://roc.zulipchat.com/#narrow/stream/304641-ideas/topic/Abilities

view this post on Zulip Richard Feldman (Jan 03 2022 at 00:34):

I want to highlight the last section of that Google doc in particular - my biggest worry about abilities, by far, is that they'll become a source of unnecessary complexity by way of being used for things that had simpler solutions which didn't involve abilities :sweat_smile:

view this post on Zulip jan kili (Jan 03 2022 at 05:23):

Ah, basically OOP leaking in?

view this post on Zulip jan kili (Jan 03 2022 at 05:24):

Great doc, and it sounds like there won't be as strong of a need for a stringify library in the future, thanks to the power of Encode.str!

view this post on Zulip jan kili (Jan 03 2022 at 05:25):

Maybe nonstandard pretty printing will still have its use cases, but I was primarily craving that easy debug logging that JS has, as you mention in the doc

view this post on Zulip jan kili (Jan 03 2022 at 05:30):

Will function definitions be able to use where/has selectors at runtime, similarly to when/is selectors? That might be very helpful.

view this post on Zulip jan kili (Jan 03 2022 at 05:31):

I assume not, since this abilities sounds like a type-level feature and the doc doesn't really reference introspection


Last updated: Jul 05 2025 at 12:14 UTC