f# - Similar to C++ access by reference? -


i'm building clustering algorithm in c++, don't deal oop , state of variables (member data) change. algorithm of complexity, find obstacle development.

so, thinking in changing programming language, 1 of functional languages: ocaml or f#. apart having change mindset on how approach programming, there's need clarified. in c++, use double end queue slide window of time through data. after period of time, oldest data removed , newer data appended. data not yet old remains in double end queue.

another, , more demanding task, compare properties of 1 of each objects. each object data period of time. , if have 1 thousand data objects @ time window, need compare each 1 between none or twenty or thirty, depending. , properties of object being compared may change result of comparison. in c++, using references, means access objects in memory, never copied, algorithm runs @ full speed (for knowledge of c++).

i've been reading functional programming, , idea each function performs operation , original data (the input) not changed. means language copies data structure , performs required transformation. if so, using functional programming delay execution of algorithm great deal. correct? if not, i.e., if there speedy way perform transformation in data, possible show me how it? small example great.

i'm hoping have kind of facility. i've read both ocaml , f# used in research , scientific projects.

at high level question whether using immutable data slower using mutable data. answer yes, slower in cases. what's surprising (to me) how small penalty is. in cases (in experience) time, log factor, worth modularity , clarity of using immutable data. , in numerous other cases there no penalty @ all.

the main reason it's not slower expect can freely reuse parts of old data. there's no need worry other part of computation change data later: it's immutable!

for similar reason, all accesses immutable data references in c++. there's no need make copies of data, other parts of computation can't change it.

if want work way, need structure data re-use. if can't this, may want use (controlled) mutation.

both ocaml , f# mixed-paradigm languages. allow use mutable data if want to.

the enlightening account of operations on immutable data (imho) chris okasaki's book purely functional data structures. (this amazon link info only, not suggestion buy book :-) can find of information in okasaki's phd thesis.


Comments

Popular posts from this blog

android - Pass an Serializable object in AIDL -

How to provide Authorization & Authentication using Asp.net, C#? -

How to use Authorization & Authentication in Asp.net, C#? -