Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ambiguity in definitions of purity and side effects #30

Open
daira opened this issue Apr 17, 2016 · 8 comments
Open

ambiguity in definitions of purity and side effects #30

daira opened this issue Apr 17, 2016 · 8 comments

Comments

@daira
Copy link

daira commented Apr 17, 2016

The definitions of purity and side effects are ambiguous. For instance, suppose we have a function that reads, but does modify, state that is reachable from its inputs. Is that a "pure" function? Typically it wouldn't be considered to be pure, but it does not have side effects as-defined, and whether it should be considered to return a value that only depends on its inputs is unclear (since the definition doesn't say that the inputs must be stateless values).

@beckyconning
Copy link

👍

@jethrolarson
Copy link
Collaborator

PRS are always welcome. Understandability is more important than accuracy in this document so if you can think of a good, simple wording I'm sure it'll get pulled

@daira
Copy link
Author

daira commented Apr 17, 2016

Feel free to assign this to me.

@hemanth
Copy link
Owner

hemanth commented Apr 22, 2016

@daira Thank you, please feel free to do a PR.

@vicentedealencar
Copy link

Untill now I understood that referencial transparency and purity were the same thing, but it turns out a function can be referentially transparent and have side effects, so it is not pure.

Any reason why Referencial Transparency is so far below purity and side-effects? I think the right order of jargons helps alot, and as I understand that purity = referential transparency + no side effects purity should be last shown of these three.

I am new to these concepts and haven't used any strictly functional language yet, so feel free to ignore me.

@clarus
Copy link

clarus commented Jul 26, 2016

A side effect is an operation which is not pure. The purity implies the referential transparency (see the confluence of the lambda calculus). A function can also be observationaly pure, but with side effects inside. For example :

function sum(a, b) {
  let s = a;
  s = s + b;
  return s;
}

We do a mutation s = s + b, so a side effect. However, the function sum is observationaly pure as it always returns the same result given the same arguments, and does not modify its environment.

@stereobooster
Copy link

Interesting classification of effects done in this paper

but the basic effects defined in Koka are total, exn, div, ndet,
alloc<h>, read<h>, write<h>, and io. Of course total is not really an effect but signifies the absence of any effect and is assigned to pure mathematical functions. When a function can throw an exception, it gets the exn effect. Potential divergence or non-termination is signified by the div effect. Currently, Koka uses a simple termination analysis based on inductive data types to assign this effect to recursive functions. Non-deterministic functions get the ndet effect. The effects alloc<h>, read<h> and write<h> are used for stateful functions over a heap h. Finally io is used for functions that do any input/output operations.
alias total = <>
alias pure = <exn, div>
alias st<h> = <alloc<h>, read<h>, write<h>>
alias io = <st<ioheap>, pure, ndet>

@stereobooster
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants