views:

443

answers:

4

The Wikipedia artcile on Effect system is currently just a short stub and I've been wondering for a while as to what is an effect system.

  • Are there any languages that have an effect system in addition to a type system?
  • What would a possible (hypothetical) notation in a mainstream language, that you're familiar, with look like with effects?
+2  A: 

(This is not an authoritative answer; just trying to trawl my memory.)

In a sense, any time you code a 'state monad' in a language, you're using the type system as a potential effect system. So "State" or "IO" in Haskell capture this notion (IO captures a whole lot of other effects as well). I vaguely remember reading papers about various languages that use advanced type systems including things like "dependent types" to control finer-grained management of effects, so that for instance the type/effect system could capture information about which memory locations would be modified in a given data type. This is useful, as it provides ways to make two functions that modify mutually exclusive bits of state be allowed to "commute" (monads don't typically commute, and different monads don't always compose well with one another, which often makes it hard to type (read: assign a static type to) 'reasonable' programs)...

An analogy at a very hand-wavy level is how Java has checked exceptions. You express extra information in the type system about certain effects (you can think of an exception as an 'effect' for the purpose of the analogy), but these 'effects' typically leak out all over your program and don't compose well in practice (you end up with a million 'throws' clauses or else resort to lots of unchecked runtime exception types).

I think a lot of research is being done in this area, both for research-y and mainstream-y languages, as the ability to annotate functions with effect information can unlock the compiler's ability to do a number of optimizations, can impact concurrency, and can do great things for various program analyses and tooling. I don't personally have high hopes for it any time soon, though, as I think lots of smart people have been working on it for a long time and there's still very little to show for it.

Brian
holy cow man, was that supposed to be English? try starting with the definition of an 'effect' and go from there. "state monad"? lol! i don't think you can assume the reader is familiar with Haskell...
Steven A. Lowe
Steven, I'm not an expert at monadic programming but I have some familiarity with Haskell.
Mark Cidade
@[marxidad]: that's great, but (a) you didn't say so in the question so it was an assumption and (b) other people will be reading the answers.
Steven A. Lowe
You know if you are reading a question about type and effect systems it would be assumed that you have some familiarity with Haskell.
1800 INFORMATION
+4  A: 
Chris Conway
+1  A: 

You can have a look at http://www.haskell.org/haskellwiki/DDC/ It's a version of haskell implementing Effect system.

skyde