caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Goswin von Brederlow <goswin-v-b@web.de>
To: caml-list@inria.fr
Subject: Re: [Caml-list] Purity in ocaml
Date: Tue, 21 Jan 2014 10:49:39 +0100	[thread overview]
Message-ID: <20140121094939.GA13578@frosties> (raw)
In-Reply-To: <CAN6ygO=D8x=6MM+=+xG30p1LNn5vj3KnYNfSE5oU+6rMCEXhMw@mail.gmail.com>

On Mon, Jan 20, 2014 at 03:45:15PM -0500, Yotam Barnoy wrote:
> I wanted to gauge the interest of people on the list in adding purity
> annotations to ocaml. Purity is one of those things that could really help
> with reducing memory allocations through deforestation and decreasing the
> running time of programs written in the functional paradigm, and it could
> be very useful for parallelism as well. The basic scheme I have in mind is
> this:
> 
> - Functions that do not access mutable structures would be marked pure.
> - Functions that access only local mutable structures would be marked as st
> (a la state monad)

Does local include the arguments passed to the function?

> - Functions that access global mutable data would be unmarked (as they are
> now).
> - Pure functions can call st functions/code so long as all of the state
> referred to by the st code is contained within said pure functions.

Because if arguments don't count this makes no sense.

But then shouldn't there be another level for functions that don't
alter its arguments?

> - Functions that call higher order functions, but do not modify mutable
> state would be marked hpure (half-pure). These functions would be pure so
> long as the functions they call remain pure. This allows List.map,
> List.fold etc to work for both pure and impure code.
> - The same thing exists for st code: hst represents functions that take
> higher order functions but only performs local state mutation.
> - In order to take advantage of this mechanism, there's no need to annotate
> functions. The type inference algorithm will figure out the strictest type
> that can be applied to a function and will save the annotation to an
> external, saved annotation file. This means that non-annotated code can
> take advantage of purity without doing any extra work, and the programmer
> never has to think about purity.
> - Having the purity annotations as an option is useful to force certain
> parts of the code, such as monads, to be pure.
> - An edge case: local state can be made to refer to global state by some
> external function call. Therefore, local state is considered 'polluted'
> (and global) if it is passed to an impure function.
> - Exceptions: not sure how to handle them yet. The easiest solution is to
> forbid them in st/pure code. Another easy alternative is to only allow
> catching them in impure code, as haskell does.
> 
> Thoughts?
> 
> -Yotam

1) What does pure mean? What does it gain you? How do you want to use it?

2) What syntax do you suggest for annotating functions?

3) Why are exceptions a problem?

4) Will this allow to annotate exceptions too so the compiler can
track which exception could be thrown and when all exceptions are
caught? If no exception can escape an function then it can be pure
again, right?

MfG
	Goswin

  parent reply	other threads:[~2014-01-21  9:49 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-01-20 20:45 Yotam Barnoy
2014-01-20 21:08 ` Siraaj Khandkar
2014-01-20 21:16   ` Yotam Barnoy
2014-01-20 21:31     ` Siraaj Khandkar
2014-01-20 21:43       ` Yotam Barnoy
2014-01-20 22:55         ` Siraaj Khandkar
2014-01-21  1:37           ` Yotam Barnoy
2014-01-21  9:49 ` Goswin von Brederlow [this message]
2014-01-21 15:27   ` Yotam Barnoy
2014-01-23  9:20     ` Goswin von Brederlow
2014-01-23  9:35       ` Arnaud Spiwack
2014-01-27  9:32         ` Goswin von Brederlow
2014-01-28  9:21           ` Arnaud Spiwack
2014-02-01 14:52             ` Goswin von Brederlow
2014-02-03  9:20               ` Arnaud Spiwack
2014-01-23 18:18       ` Yotam Barnoy
2014-01-27  9:46         ` Goswin von Brederlow
2014-01-29 17:16           ` Yotam Barnoy
2014-02-01 15:03             ` Goswin von Brederlow

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20140121094939.GA13578@frosties \
    --to=goswin-v-b@web.de \
    --cc=caml-list@inria.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).