9 research outputs found

    Implementing functional programs using mutable abstract data types

    Get PDF
    Journal ArticleWe study the following problem in this paper. Suppose we have a purely functional program that uses a set of abstract data types by invoking their operations. Is there an order of evaluation of the operations in the program that preserves the applicative order of evaluation semantics of the program even when the abstract data types behave as mutable modules. An abstract data type is mutable if one of its operations destructively updates the object rather than returning a new object as a result. This problem is important for several reasons. It can help eliminate unnecessary copying of data structure states. It supports a methodology in which one can program in a purely functional notation for purposes of verification and clarity, and then automatically transform the program into one in a n object oriented, imperative language, such as CLU, ADA, Smalltalk, etc., that supports abstract data types. It allows accruing both the benefits of using abstract data types in programming, and allows modularity and verifiability

    Funktionaalinen ohjelmointiparadigma web-käyttöliittymäkehityksessä

    Get PDF
    Tiivistelmä. Nykyaikaisten web-sovellusten lisääntynyt interaktiivisuus ja uudenlaiset teknologiat — kuten mobiili- ja muut älylaitteet — ovat lisänneet web-käyttöliittymiin kohdistuvia vaatimuksia, mikä on lisännyt tarvetta kehittää uusia näkökulmia, lähestymistapoja ja teknologioita web-käyttöliittymäkehitykseen. Funktionaalinen ohjelmointi on lambdakalkyyliin perustuva ohjelmointiparadigma. Paradigmalla on pitkä historia, ja siitä on tehty lukuisia tieteellisiä tutkimuksia. Yleinen vertailukohde on imperatiivinen ohjelmointiparadigma, johon suurin eroavaisuus löytyy sivuvaikutuksien puutteesta ja siitä seuraavista eduista ja haitoista. Tässä tutkielmassa tarkastellaan kirjallisuuskatsauksen keinoin, mitä funktionaalisen ohjelmointiparadigman tärkeimpiä ominaisuuksia voidaan hyödyntää web-käyttöliittymäkehityksessä, ja millä tavalla niitä voidaan hyödyntää. Vastauksena tutkimuskysymykseen tutkielma osoittaa kaikkien funktionaalisen ohjelmoinnin tärkeimpien ominaisuuksien hyödyntämisen olevan web-käyttöliittymäkehityksessä mahdollista, mutta osoittaa myös tarpeen JavaScript-kirjastojen tai vaihtoehtoisten ohjelmointikielten käytölle. Tutkielma esittää myös tarjottavien ratkaisujen seuraukset, ja tarpeen uusien teknologioiden ja esitettyjen ratkaisujen soveltuvuuden lisätutkimukselle

    遅延評価に基づく関数型言語におけるメモリ割当量の削減

    Get PDF
    遅延評価は,値が実際に必要になるまで計算を遅らせる評価戦略である.必要になった値から計算するため,最終結果を求めるのに不要な計算を除去し,計算の最適化を目指すことができる.それと同時に,どの値が必要となるかという判断を処理系に任せることによって,プログラムに計算の進め方を記述する必要がなくなり,宣言的で簡潔なプログラムの記述につながる.たとえば,リストなどの再帰的データ構造を扱う際には,そのデータ構造を生成する処理と読み進める処理を分けて記述することができるため,遅延評価により得られる記述面での恩恵は大きい.記述面での利点が多い一方で,遅延評価を行う言語処理系を実装するには,計算の遅延に必要となるオブジェクト(遅延オブジェクト,以下サンクと呼ぶ)について,十分考慮して処理系を設計する必要がある.特に,サンクをメモリ上に割り当てる時間的・空間的コストが問題となり,遅延評価によって不要な計算を除去できるとしても,プログラムの実行時のオーバヘッドが大きくなってしまうという問題点がある.そのため,効率的な遅延評価機構の実現を目指して,サンクの生成を抑制する静的解析手法について今まで多くの研究がなされてきた.たとえば,正格性解析は,プログラムの最終結果を求めるために必要となる計算を,プログラムから静的に解析する.値が必要となる式は遅延させずに済ませることができるため,その式に対するサンクを生成しない効率的なコードを生成することができる.多くのプログラムにおいて,正格性解析によりサンクの生成を抑えられることは,すでに確認されているが,プログラムの文面から得られる静的な情報のみを用いるため,動的なふるまいを考慮すれば削減可能と判断できるようなサンクは,正格性解析による削減の対象ではない.たとえば,リストをどれだけの長さ読み進めるかというような実行時に決定する要素があると,リストの遅延に必要となるサンクの生成を正格性解析のみで抑制することは難しい.本論文は,サンクの削減という目的を達成するため,リストのような線形再帰的に定義される代数データ構造に注目し,既存のサンクを再利用する手法Thunk Recycling を提案する.Thunk Recycling は,すでに割り当てられているサンクを破壊的に更新して再利用し,新たなサンクの生成を抑える.たとえば,リストであれば,後続のリストの生成を遅延するサンクを再利用できる.本論文では,まず,Thunk Recycling の動作について述べ,その実現に必要となる機構についてまとめる.再利用を可能とするために,再利用が可能であるサンクを既存のサンクと区別して扱う.再利用機構は,破壊的な更新により矛盾が起こらないようにするコンパイル時の変換機構と,実行時に再利用を行う機構から構成される.プログラム変換の基本的な方針は,再利用可能なサンクへの参照を単一にすることである.また,実行時の再利用機構は,既存のサンクの生成・評価という仕組みの多くの部分を流用する.次に,Thunk Recycling の形式的な定義と,その正しさの証明について述べる.簡単な関数型言語を定義し,その言語に対するThunk Recycling のプログラム変換を定義した.さらに,サンクを再利用する操作的意味論を定義した.その意味論を用いて,Thunk Recycling の適用の有無により,プログラムのふるまいが変わらないことを証明した.次に,関数型プログラミング言語Haskell の処理系であるGlasgow Haskell Compiler(GHC)へのThunk Recycling の実装について述べる.GHC は,Haskell の標準的な処理系であり,多くの研究の基盤として用いられ,新しい言語概念など先進的な研究成果が取り入れられている.本論文では,Thunk Recycling の機構のGHC における実装について,考えうる各種の設計方針と,それぞれの設計方針を選択するに至った設計上の得失に関して論じる.GHC は,その大部分が関数型言語であるHaskell で記述されており,関数型言語による大規模で洗練されたシステムであるという面を持つ.そのため,Thunk Recycling の実装は,関数型言語による大規模なソフトウェアに対する開発事例の一例となっている.そこで,本論文では,関数型言語で書かれたプログラミング言語処理系に変更を加えるという観点から,遅延評価を行う関数型言語処理系の実装に関して得られた知見を論じる.最後に,GHC 上の実装について,ベンチマークプログラムを用いた実験について述べる.実行時間に関しては,適用するプログラムを選ぶものの,再利用によって総メモリ割当量を削減できた.電気通信大学201

    First Class Copy & Paste

    Get PDF
    The Subtext project seeks to make programming fundamentally easier by altering the nature of programming languages and tools. This paper defines an operational semantics for an essential subset of the Subtext language. It also presents a fresh approach to the problems of mutable state, I/O, and concurrency.Inclusions reify copy & paste edits into persistent relationships that propagate changes from their source into their destination. Inclusions formulate a programming language in which there is no distinction between a programÂs representation and its execution. Like spreadsheets, programs are live executions within a persistent runtime, and programming is direct manipulation of these executions via a graphical user interface. There is no need to encode programs into source text.Mutation of state is effected by the computation of hypothetical recursive variants of the state, which can then be lifted into new versions of the state. Transactional concurrency is based upon queued single-threaded execution. Speculative execution of queued hypotheticals provides concurrency as a semantically transparent implementation optimization

    Shared Integer Dichotomy

    Get PDF
    The Integer Dichotomy Diagram IDD(n) represents a natural number n ∈ N by a Directed Acyclic Graph in which equal nodes are shared to reduce the size s(n). That IDD also represents some finite set of integers by a Digital Search DAG where equal subsets are shared. The same IDD also represents representing Boolean Functions, IDDs are equivalent to (Zero-suppressed) ZDD or to (Binary Moment) BMD Decision Diagrams. The IDD data-structure and algorithms combines three standard software packages into one: arithmetics, sets and Boolean functions. Unlike the binary length l(n), the IDD size s(n) < l(n) is not monotone in n. Most integers are dense, and s(n) is near l(n). Yet, the IDD size of sparse integers can be arbitrarily smaller. We show that a single IDD software package combines many features from the best known specialized packages for operating on integers, sets, Boolean functions, and more. Over dense structures, the time/space complexity of IDD operations is proportional to that of its specialized competitors. Yet equality testing is performed in unit time with IDDs, and the complexity of some integer operations (e.g. n < m, n ± 2 m , 2 2 n ,. . .) is exponentially lower than with bit-arrays. In general, the IDD is best in class over sparse structures, where both the space and time complexities can be arbitrarily lower than those of un-shared representations. We show that sparseness is preserved by most integer operations, including arithmetic and logic operations, but excluding multiplication and division. Keywords: computer arithmetic, integer dichotomy & trichotomy, sparse & dense structures , dictionary package, digital search tree, minimal acyclic automata, binary Trie, boolean function, decision diagram, store/compute/code once.

    A uniform treatment of order of evaluation and aggregate update

    Get PDF
    The article presents an algorithm for the destructive update optimization in first-order lazy functional languages. The main component of the method is a new static analysis of the order of evaluation of expressions which, compared to other published work, has a much lower complexity and is not restricted to pure lazy evaluation. The other component, which we call reduction to variables, is a method of detecting the variables which denote locations where the result of an expression might be stored.Starting with the operational semantics of the language, we introduce some markers for the values in the basic domain. By choosing appropriately the set of markers M and the method of propagating them during evaluation, we can extract some property of the evaluation in which an expression can participate by looking at the marker of its value. We then define an equivalent denotational semantics and derive the above analyses, in a uniform way, by abstract interpretation over a subdomain of P(M[perpendicular]).Peer Reviewedhttp://deepblue.lib.umich.edu/bitstream/2027.42/30571/1/0000206.pd

    FP2: Fully in-Place Functional Programming

    Get PDF
    As functional programmers we always face a dilemma: should we write purely functional code, or sacrifice purity for efficiency and resort to in-place updates? This paper identifies precisely when we can have the best of both worlds: a wide class of purely functional programs can be executed safely using in-place updates without requiring allocation, provided their arguments are not shared elsewhere. We describe a linear fully in-place (FIP) calculus where we prove that we can always execute such functions in a way that requires no (de)allocation and uses constant stack space. Of course, such a calculus is only relevant if we can express interesting algorithms; we provide numerous examples of in-place functions on datastructures such as splay trees or finger trees, together with in-place versions of merge sort and quick sort. We also show how we can generically derive a map function over any polynomial data type that is fully in-place. Finally, we have implemented the rules of the FIP calculus in the Koka language. Using the Perceus reference counting garbage collection, this implementation dynamically executes FIP functions in-place whenever possibl
    corecore