Re: [go-nuts] pure function on golang

2020-07-13 Thread Kurniagusta Dwinto
Hello guys, thanks for the response, After brainstorming for a while, I think we can implement this without changes in the language, and create static analysis tools for it, What's wrong with my approach before is using the suffix "Pure" as a pure function marker, which is unreliable because

Re: [go-nuts] pure function on golang

2020-07-08 Thread Jesper Louis Andersen
On Mon, Jul 6, 2020 at 6:46 PM wrote: > > 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

Re: [go-nuts] pure function on golang

2020-07-07 Thread Haddock
> the name "pure" may be debatable, but the characteristic is the same with "constexpr" in C++, although I also don't have a strong reason why this is important beside separation IO and non-IO D is a lange that has true pure functions, see https://dlang.org/spec/function.html#pure-functions

Re: [go-nuts] pure function on golang

2020-07-07 Thread Michael Jones
The standard math library is a natural, easy gateway; a simple preprocessor could do it. maybe i'll prototype it. On Tue, Jul 7, 2020 at 4:43 AM Brian Candler wrote: > On Tuesday, 7 July 2020 01:46:48 UTC+1, Kurniagusta Dwinto wrote: >> >> > i would value "pure" if it were a contract for early

Re: [go-nuts] pure function on golang

2020-07-07 Thread Brian Candler
On Tuesday, 7 July 2020 01:46:48 UTC+1, Kurniagusta Dwinto wrote: > > > i would value "pure" if it were a contract for early evaluation > does this "early evaluation" concern about IO? like loading blob data with > ioutil.ReadFile into global variable at compile time? > I think by definition,

Re: [go-nuts] pure function on golang

2020-07-06 Thread Kurniagusta Dwinto
> i would value "pure" if it were a contract for early evaluation does this "early evaluation" concern about IO? like loading blob data with ioutil.ReadFile into global variable at compile time? > Well, C++ is a very different language with very different goals. I > think history shows that C++

Re: [go-nuts] pure function on golang

2020-07-06 Thread Ian Lance Taylor
On Mon, Jul 6, 2020 at 5:11 PM Kurniagusta Dwinto wrote: > > > It's not obvious to me that "pure" is a characteristic that is important > > enough > > to be singled out and added to the language > > the name "pure" may be debatable, but the characteristic is the same with > "constexpr" in C++,

Re: [go-nuts] pure function on golang

2020-07-06 Thread Michael Jones
i would value "pure" if it were a contract for early evaluation. in my post on this from 2018 (linked above), the reasoning was so that "x := math.Sin(0.23)" would be a compile-time event. On Mon, Jul 6, 2020 at 5:11 PM Kurniagusta Dwinto wrote: > > It's not obvious to me that "pure" is a

Re: [go-nuts] pure function on golang

2020-07-06 Thread Kurniagusta Dwinto
> It's not obvious to me that "pure" is a characteristic that is important enough > to be singled out and added to the language the name "pure" may be debatable, but the characteristic is the same with "constexpr" in C++, although I also don't have a strong reason why this is important beside

Re: [go-nuts] pure function on golang

2020-07-06 Thread Ian Lance Taylor
On Mon, Jul 6, 2020 at 4:52 PM Kurniagusta Dwinto wrote: > > Adding pure marker will give information to the programmer that the function > will not do any side effect, the compiler just gives compile error when the > programmer disagrees about the contract, like doing IO operation on pure >

Re: [go-nuts] pure function on golang

2020-07-06 Thread Kurniagusta Dwinto
Additionally, this feature complement new generic feature, this feature will help anyone that trying to use functional programming pattern (like monad pattern) in their code On Tuesday, July 7, 2020 at 6:52:31 AM UTC+7 Kurniagusta Dwinto wrote: > Adding pure marker will give information to the

Re: [go-nuts] pure function on golang

2020-07-06 Thread Kurniagusta Dwinto
Adding pure marker will give information to the programmer that the function will not do any side effect, the compiler just gives compile error when the programmer disagrees about the contract, like doing IO operation on pure function. So in the end, this feature focuses on helping the

Re: [go-nuts] pure function on golang

2020-07-06 Thread Ian Lance Taylor
On Mon, Jul 6, 2020 at 3:11 PM bugpowder wrote: > > 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? The compiler can already tell whether

Re: [go-nuts] pure function on golang

2020-07-06 Thread Michael Jones
prior discussion: https://groups.google.com/forum/#!searchin/Golang-Nuts/pure$20functions/golang-nuts/ZVeMxBBVpa4/slidZL9KBAAJ On Mon, Jul 6, 2020 at 3:11 PM bugpowder wrote: > I'd guess the compiler could then enforce it (see if any non-pure marked > function is called from a pure one), it

Re: [go-nuts] pure function on golang

2020-07-06 Thread bugpowder
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 wrote: > On Mon, Jul 6, 2020 at 9:47 AM wrote:

Re: [go-nuts] pure function on golang

2020-07-06 Thread Ian Lance Taylor
On Mon, Jul 6, 2020 at 9:47 AM 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

[go-nuts] pure function on golang

2020-07-06 Thread kurnia . d . win
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