首页 | 本学科首页   官方微博 | 高级检索  
相似文献
 共查询到19条相似文献,搜索用时 156 毫秒
1.
泛型即通过参数化类型来实现在同一份代码上操作多种数据类型.泛型编程是一种编程范式,它利用“参数化类型”将类型抽象化,实现灵活的软件复用.泛型编程思想已经在多种语言中得到运用,并已取得了不小的成果.文中旨在Haskell语言上进行泛型的研究与应用,Haskell语言是一门广为流行的函数式语言,它的计算模型简单,程序语法清晰,易于编写,易于维护.文中利用一些规则对Haskell语言的语法进行扩展,同时引入泛型编程的思想来研究新的函数定义方法,最后在Haskell语言上实现泛型功能.  相似文献   

2.
对于泛型程序设计来说,类型理论中的参数化多态是其理论框架,因为参数化多态引入了类型变量,使得类型参数化,从而完全支持类型上的抽象。然而对于现行的泛型算法,无论是C++标准模版库中的泛型算法还是基于函数式程序设计语言的算法,函数功能的定义比较具体化、单一化,因而缺乏可扩展性和高度的复用性。将对递归算法进行抽象,构造原始递归构造子,使得一般的泛型算法都可以通过该算子来构造,从而加强泛型算法的可复用型与可扩展性。除此之外,分析了递归算法构造子与泛型程序设计中的iterator概念和用于描叙泛型概念的形式化语言Tecton中所提倡的reuse概念的一致性。也给出算法复杂度的定量分析,并用函数式语言ML来实现。  相似文献   

3.
对于泛型程序设计来说,类型理论中的参数化多态是其理论框架,因为参数化多态引入了类型变量,使得类型参数化,从而完全支持类型上的抽象.然而对于现行的泛型算法,无论是C 标准模版库中的泛型算法还是基于函数式程序设计语言的算法,函数功能的定义比较具体化、单一化,因而缺乏可扩展性和高度的复用性.将对递归算法进行抽象,构造原始递归构造子,使得一般的泛型算法都可以通过该算子来构造,从而加强泛型算法的可复用型与可扩展性.除此之外,分析了递归算法构造子与泛型程序设计中的iterator概念和用于描叙泛型概念的形式化语言Tecton中所提倡的reuse概念的一致性.也给出算法复杂度的定量分析,并用函数式语言ML来实现.  相似文献   

4.
王朋  徐健  于尚超 《微机发展》2013,(7):92-95,100
泛型编程旨在编写一般化并可重复使用的算法,主要目的是提高程序的复用性,其效率与针对某特定数据类型而设计的算法相同。泛型编程可以使算法与数据结构完全分离,极大提高了程序的灵活性。在O’Caml语言中已经实现了类型标记函数和泛型函数,但泛型函数的类型参数只能是基本类型或实例化类型,不能使用抽象类型。"泛型抽象"是指使用抽象类型作为类型参数的函数定义方法,实现了"泛型编程"类型参数的多样化。文中在O’Caml语言上进行"泛型抽象"的研究,根据规则对O’Caml语言语法进行扩展,并在O’Caml语言中实现了"泛型抽象"函数定义。  相似文献   

5.
泛型编程旨在编写一般化并可重复使用的算法,主要目的是提高程序的复用性,其效率与针对某特定数据类型而设计的算法相同.泛型编程可以使算法与数据结构完全分离,极大提高了程序的灵活性.在O'Caml语言中已经实现了类型标记函数和泛型函数,但泛型函数的类型参数只能是基本类型或实例化类型,不能使用抽象类型.“泛型抽象”是指使用抽象类型作为类型参数的函数定义方法,实现了“泛型编程”类型参数的多样化.文中在O'Caml语言上进行“泛型抽象”的研究,根据规则对O'Caml语言语法进行扩展,并在O'Caml语言中实现了“泛型抽象”函数定义.  相似文献   

6.
一类递归函数的多态类型   总被引:1,自引:0,他引:1       下载免费PDF全文
黄文集 《软件学报》2004,15(7):969-976
以上下文无关语言上的递归函数为基础的语言LFC(1anguage for context free recursive function)是一种形式规约语言,适于处理短语结构.LFC也是函数式语言,具有函数式语言的许多特点.LFC已经在形式规约获取系统SAQ(specification acquisition system)中实现,为其最初设计的类型系统不支持多态类型.引入类型变量和相应的类型检查方法,就可以将其类型系统扩充为多态类型系统.对多态类型系统实现中的一些问题也进行了讨论.在实现多态之后,LFC  相似文献   

7.
基于程序演化的决策树优化算法   总被引:1,自引:0,他引:1  
决策树算法的优化问题一直是一个倍受国内外关注的领域,由此已经提出了很多优化方法,并取得了很好的成果.在总结已有成果的基础上,在决策树的优化问题中,引入程序演化的思想,得到具有更高效率的决策树.运用函数式语言所具有的代数性质,首先对标准的ID3决策树算法进行Haskell语言描述,研究应用程序演化策略,推衍出一种高效等价算法.实验结果证明演化出的算法是正确和高效的.  相似文献   

8.
O’Caml语言是一门优秀的函数式程序语言,具有计算模型简单、语法语义描述清晰等特点,而通用编程技术方法通过高度抽象算法、数据结构及其他软件组件可以避免功能相似代码的重复编写。针对如何将通用编程技术方法和O’Caml语言相结合来提高O’Caml程序复用程度的问题,通过对O’Caml语言语法进行扩展引入类型标记1函数,然后运用类型结构化转换和类型映射机制,实现通用函数,从而达到在O’Caml语言中引入通用编程技术的目的。实例结果表明,在O’Caml语言中实现通用编程技术,有效提高了编程效率和程序的通用性。  相似文献   

9.
本文介绍基于函数式语言的元编程系统,讨论元编程系统特别是同构系统的语言特点。从程序反射的角度分析元编程系统对程序设计语言在自我表示、自我分析和控制等方面的要求。以 MetaML 和 Template Haskell 为例论述在函数式语言中为了支持元编程需要扩展的机制,包括语法、语义、类型系统、安全的变量使用等,以及它们的实现方案、各方案的特点。最后总结一些元编程系统的共同点,并预测未来的发展趋势。  相似文献   

10.
一种带约束的多态类型系统   总被引:1,自引:0,他引:1  
本文讨论了一种带约束的多态类型系统,引入了约束类型,约束与全称量化的结合使得参数化多态函数的应用更安全,同时也为重工的表示和实现提供了一个新的途径,提高了类型表示的抽象度。本文讨论的类型系统具有两个不同层次的类型结构,约束的引入与肖去是不同层次上的操作,最后,本文人出了类型检查算法Wr,并证明了此算法中约束的可满足性是可判定的。  相似文献   

11.
Programmable rewriting strategies provide a valuable tool for implementing traversal functionality in grammar-driven (or schema-driven) tools. The working Haskell programmer has access to programmable rewriting strategies via two similar options: (i) the Strafunski bundle for generic functional programming and language processing, and (ii) the “Scrap Your Boilerplate” approach to generic functional programming. Basic rewrite steps are encoded as monomorphic functions on datatypes. Rewriting strategies are polymorphic functions composed from appropriate basic strategy combinators.We will briefly review programmable rewriting strategies in Haskell. We will address the following questions:
• What are the merits of Haskellish strategies?
• What is the relation between strategic programming and generic programming?
• What are the challenges for future work on functional strategies?
Keywords: Rewrite startegies; programming languages; Haskell; functional programming  相似文献   

12.
13.
Although the principles behind generic programming are already well understood, this style of programming is not widespread and examples of applications are rarely found in the literature. This paper addresses this shortage by presenting a new method, based on generic programming, to automatically visualize recursion trees of functions written in Haskell. Crucial to our solution is the fact that almost any function definition can be automatically factorized into the composition of a fold after an unfold of some intermediate data structure that models its recursion tree. By combining this technique with an existing tool for graphical debugging, and by extensively using Generic Haskell, we achieve a rather concise and elegant solution to this problem.  相似文献   

14.
Plover is an automated property-verifier for Haskell programs that has been under development for the past three years as a component of the Programatica project. In Programatica, predicate definitions and property assertions written in P-logic, a programming logic for Haskell, can be embedded in the text of a Haskell program module. Properties refine the type system of Haskell but cannot be verified by type-checking alone; a more powerful logical verifier is needed.Plover codes the proof rules of P-logic, and additionally, embeds strategies and decision procedures for their application and discharge. It integrates a reduction system that implements a rewriting semantics for Haskell terms with a congruence-closure algorithm that supports reasoning with equality. It employs strategies such as structure splitting and case analysis to explore alternative valuations of expressions of type Bool or other finite data types, but these strategies can lead to exponential growth of terms and must be employed cautiously.Plover itself is written in Stratego, which has proven to be a powerful language tool for implementating a verifier. We discuss the design and implementation of some strategies that enable Plover to comprehend Haskell and verify many valid property assertions.  相似文献   

15.
Initial algebra semantics is one of the cornerstones of the theory of modern functional programming languages. For each inductive data type, it provides a Church encoding for that type, a build combinator which constructs data of that type, a fold combinator which encapsulates structured recursion over data of that type, and a fold/build rule which optimises modular programs by eliminating from them data constructed using the buildcombinator, and immediately consumed using the foldcombinator, for that type. It has long been thought that initial algebra semantics is not expressive enough to provide a similar foundation for programming with nested types in Haskell. Specifically, the standard folds derived from initial algebra semantics have been considered too weak to capture commonly occurring patterns of recursion over data of nested types in Haskell, and no build combinators or fold/build rules have until now been defined for nested types. This paper shows that standard folds are, in fact, sufficiently expressive for programming with nested types in Haskell. It also defines buildcombinators and fold/build fusion rules for nested types. It thus shows how initial algebra semantics provides a principled, expressive, and elegant foundation for programming with nested types in Haskell.  相似文献   

16.
苏锦钿  余珊珊 《计算机科学》2011,38(7):144-147,156
函数式程序语言Haskell中的Monads理论在描述上下文依赖计算等方面存在一定的不足。作为Monads的范畴论对偶概念,Comonads理论可以有效地提高Haskell对上下文依赖计算的描述能力。首先给出Comonads的范畴论定义和性质,以及Comonads在Haskell的具体实现;接着探讨Comonads的CoKleisfi三元组和CoKleisli范畴,通过实例说明如何将其应用于上下文依赖计算的描述和推理中;最后进一步研究Comonads与Monads之间的分配律,指出如何通过分配律将效果计算与上下文依赖计算有机地融合起来。  相似文献   

17.
Haskell has a sophisticated mechanism for overloading identifiers with multiple definitions at distinct types. Object-oriented programming has a similar notion of overriding and overloading for methods names. Unfortunately, it is not possible to encode object-oriented overloading directly using Haskell overloading. This deficiency becomes particularly tiresome when Haskell programs wish to call methods imported from an object-oriented library.We present two refinements of Haskell's type class system: Closed classes and overlapping instances. We demonstrate how we may exploit the refined system so as to be able to encode object-oriented classes within Haskell. This encoding allows us to mimic, within Haskell, the overloading resolution rules employed by object-oriented languages without the need for additional type annotations or name mangling. As a consequence, object-oriented class libraries are very convenient to import and use within Haskell.We thank Don Syme, Nick Benton, Andrew Kennedy, and the anonymous reviewers, for many helpful comments.  相似文献   

18.
本文对泛型编程的核心思想和技术特征进行了较为深入的分析,介绍了泛型编程在语言实现上的现状与不足,着重论述了作者针对这些不足做出的改进工作,即对类型参数及其约束机制进行扩展以支持通用、高效的算法和数据结构的设计,并以Java语言作为实施例,详细介绍了如何通过现有对象技术来实现比较完整的泛型编程,是现有面向对象语类泛型编程的首例。  相似文献   

19.
STL是采用泛型编程思想设计的C 通用组件库。函数对象在STL中具有重要作用,它可以进一步提高算法的通用性,增强核心组件的功能。本文在简要介绍函数对象的基础上,讨论了它在STL中的应用。  相似文献   

设为首页 | 免责声明 | 关于勤云 | 加入收藏

Copyright©北京勤云科技发展有限公司  京ICP备09084417号