I'd guess the compiler could then enforce it (see if any non-pure marked
function is called from a pure one), it could exploit it (e.g. play with
evaluation order, cache, etc), and other such things?

On Tue, Jul 7, 2020 at 1:00 AM Ian Lance Taylor <i...@golang.org> wrote:

> On Mon, Jul 6, 2020 at 9:47 AM <kurnia.d....@gmail.com> wrote:
> >
> > Hi, I don't know if this kind of idea is already discussed before.
> >
> > I have an idea of adding pure function marker/type on golang, it is just
> like "constexpr" on C++ or "const fn" on Rust, whether this function is
> evaluated at compile time if the input is known at compile time is another
> discussion,
> > I don't think this idea is hard to implement
> >
> > to my understanding, a pure function is a function that doesn't have a
> side effect, so we can limit pure function to:
> > - unable to call non-pure function
> > - unable to modify a variable that is not declared on current function
> (like a global variable)
> >
> > for this purpose, we can think receiver as input to the function
>
> ...
>
> > what do you guys think about this idea?
>
> You didn't really explain what we would gain by adding this to the
> language.  It's clearly already possible to write pure functions.  How
> does it help to add the ability to explicitly mark a function as pure?
>
> Ian
>
> --
> You received this message because you are subscribed to the Google Groups
> "golang-nuts" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to golang-nuts+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/golang-nuts/CAOyqgcXOdCc8Zz8mXAmghLm%2B6%3Dvi8S8zG_3Phrv2Hy-w%3Dm70kQ%40mail.gmail.com
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/CAACdnTAKTKQxU_K5xRqHGDKKBEhyTAq6%3D6q1HK%2BgDUewgJW1aw%40mail.gmail.com.

Reply via email to