Stream: ideas

Topic: Marking a pure function impure should maybe be a warning


view this post on Zulip Eli Dowling (Dec 01 2024 at 08:53):

I just noticed that I can mark a function that does no effects as effectful

pureFunc! : _ => Str
pureFunc! =\a-> "hi $(a)"

At which point the compiler thinks it's effectful and will show warnings for code like this

pureFunc2 : Str -> Str
pureFunc2 = \a ->pureFunc! a

What do we all think about this?

view this post on Zulip Sam Mohr (Dec 01 2024 at 09:07):

I think the first one should be allowed for things we expose to the host (and probably also stuff exposed from a module), and disallowed otherwise. The second one is good though IMO

view this post on Zulip Anton (Dec 01 2024 at 11:29):

I remember we have this general convention of believing the type signature, which I assume is for a good reason

view this post on Zulip Sam Mohr (Dec 01 2024 at 11:45):

I think in the static dispatch world, we'll want to "implement an interface" by exposing functions from a module. I don't think that implementing an effectful interface should always require an actual effect to be performed

view this post on Zulip Sam Mohr (Dec 01 2024 at 11:46):

For example, what if my tracing framework takes any function that's effectful: can I not trace any pure functions?

view this post on Zulip Eli Dowling (Dec 01 2024 at 12:02):

Sam Mohr said:

For example, what if my tracing framework takes any function that's effectful: can I not trace any pure functions?

That's a very compelling argument. Implementing an interface that's effectful in a pure way, makes perfect sense to me.

view this post on Zulip Brendan Hansknecht (Dec 01 2024 at 17:10):

A pure function can always be promoted to effectful. So that shouldn't be an issue

view this post on Zulip Brendan Hansknecht (Dec 01 2024 at 17:12):

@Eli Dowling with your original comment:
I think pureFunc! should give a warning for being incorrectly labelled as effectful.

pureFunc2 should also give a warning for calling an effectful function but not being effectful

view this post on Zulip Brendan Hansknecht (Dec 01 2024 at 17:17):

At the same time, it is important to remember that pure functions can always unify to effectful.

So this code should be warning free

runStrEffect! : ({} => Str) => Str
runStrEffect! = \fn! -> fn! {}

pureStrFn : {} -> Str
pureStrFn = \{} -> "output"

runStrEffect! pureStrFn

view this post on Zulip Brendan Hansknecht (Dec 01 2024 at 17:18):

This is how I would expect many potentially effectful interfaces to be written via static dispatch.

view this post on Zulip Richard Feldman (Dec 01 2024 at 17:34):

Brendan Hansknecht said:

Eli Dowling with your original comment:
I think pureFunc! should give a warning for being incorrectly labelled as effectful.

yeah kinda like unused arguments - "this isn't going to break anything, but fyi you have an opportunity to simplify this function"


Last updated: Jun 16 2026 at 16:19 UTC