In Object Oriented Paradigm, I would create an object/conceptual model before I start implementing it using OO language.
在面向对象的范例中,我将在使用OO语言开始实现它之前创建一个对象/概念模型。
Is there anything parallel to object model in functional programming. Is it called functional model? or we create the same conceptual model in both the paradigm before implementing it in one of the language..
在函数式编程中是否有与对象模型平行的东西。它被称为功能模型吗?或者我们在范例中创建相同的概念模型,然后在其中一种语言中实现它。
Are there articles/books where I can read about functional model in case it exist?
有文章/书籍,我可以阅读有关功能模型的内容吗?
or to put it in different way... even if we are using functional programming language, would we start with object model?
或者以不同的方式...即使我们使用函数式编程语言,我们会从对象模型开始吗?
3 个解决方案
#1
6
In fact there is. There is a form of specification for functional languages based on Abstract Data Types called algebraic specification. Their behavior is very similar to that of objects in some ways, however the constructs are logical and mathematical, and are immutable like functional constructs.
实际上有。基于抽象数据类型的函数语言有一种称为代数规范的规范形式。它们的行为在某些方面与对象的行为非常相似,但是构造是逻辑和数学的,并且像函数构造一样是不可变的。
A particular functional specification language that's used in the Algorithms and Data Structures class in the University of Buenos Aires has generators, observers, and additional operations. A generator is an expression that is both an instance and a possible composition of the data type. For example, for a binary tree (ADT bt), we have null nodes, and binary nodes. So we would have the generators:
在布宜诺斯艾利斯大学的算法和数据结构课程中使用的特定功能规范语言具有生成器,观察器和附加操作。生成器是一个表达式,它既是实例又是数据类型的可能组合。例如,对于二叉树(ADT bt),我们有空节点和二进制节点。所以我们会有发电机:
-nil
-bin(left:bt, root: a, right:bt)
Where left is an instance of a bt, the root is a generic value, and right is another bt. So, nil is a valid form of a bt, but bin(bin(nil,1,nil),2,nil) is also valid, representing a binary tree with a root node with a value of 2, a left child node with a value of 1, and a null child right node.
左边是bt的实例,root是泛型值,右边是另一个bt。因此,nil是bt的有效形式,但bin(bin(nil,1,nil),2,nil)也是有效的,表示具有值为2的根节点的二叉树,左子节点值为1,以及null子右节点。
So for a function that say, calculates the number of nodes in a tree, you define an observer of the ADT, and you define a set of axioms which map to each generator. So, for example:
因此,对于一个函数,即计算树中节点的数量,您可以定义ADT的观察者,并定义一组映射到每个生成器的公理。所以,例如:
numberOfNodes(nil) == 0
numberOfNodes(bin(left,x,right))== 1 + numberOfNodes(left) + numberOfNodes(right)
This has the advantage of using recursive definitions of operations, and has the more, formally interesting property that you can use something called structural induction to PROVE that your specification is correct (yes, you demonstrate that your algorithm will produce the proper result).
这具有使用递归操作定义的优点,并且具有更多,正式有趣的属性,您可以使用称为结构归纳的东西来证明您的规范是正确的(是的,您证明您的算法将产生正确的结果)。
This is a fairly academic topic rarely seen outside of academic circles, but it's worth it to get an insight on program design that may change the way you think about algorithms and data structures. The proper bibliography includes:
这是一个在学术界很少见到的相当学术的话题,但是有必要深入了解程序设计,这可能会改变您对算法和数据结构的看法。适当的参考书目包括:
Bernot, G., Bidoit, M., and Knapik, T. 1995. Observational specifications and the indistinguishability assumption. Theor. Comput. Sci. 139, 1-2 (Mar. 1995), 275-314. DOI= http://dx.doi.org/10.1016/0304-3975(94)00017-D
Bernot,G.,Bidoit,M。和Knapik,T。1995.观察规范和不可区分性假设。理论值。 COMPUT。科学。 139,1-2(1995年3月),275-314。 DOI = http://dx.doi.org/10.1016/0304-3975(94)00017-D
Guttag, J. V. and Horning, J. J. 1993. Larch: Languages and Tools for Formal Specification. Springer-Verlag New York, Inc. Abstraction and Specification in Software Development, Barbara Liskov y John Guttag, MIT Press, 1986.
Guttag,J.V。和Horning,J.J.1993。落叶松:正式规范的语言和工具。 Springer-Verlag New York,Inc。软件开发中的抽象和规范,Barbara Liskov和John Guttag,麻省理工学院出版社,1986年。
Fundamentals of Algebraic Specification 1. Equations and Initial Semantics. H. Ehrig y B. Mahr Springer-Verlag, Berlin, Heidelberg, New York, Tokyo, Germany, 1985.
代数规范的基本原理1.方程和初始语义。 H. Ehrig y B. Mahr Springer-Verlag,柏林,海德堡,纽约,东京,德国,1985年。
With corresponding links: http://www.cs.st-andrews.ac.uk/~ifs/Resources/Notes/FormalSpec/AlgebraicSpec.pdf http://nms.lcs.mit.edu/larch/pub/larchBook.ps
使用相应的链接:http://www.cs.st-andrews.ac.uk/~ifs/Resources/Notes/FormalSpec/AlgebraicSpec.pdf http://nms.lcs.mit.edu/larch/pub/larchBook。 PS
It's a heck of an interesting topic.
这是一个有趣的话题。
#2
1
In both OO and FP paradigms, you form your domain model (the problem you're solving) and then create objects in your program to mirror the domain objects. There are some differences, in that how the program objects mirror the domain objects is influenced by the paradigm and langauge you're using. Some examples (in Haskell):
在OO和FP范例中,您构建域模型(您正在解决的问题),然后在程序中创建对象以镜像域对象。存在一些差异,因为程序对象如何镜像域对象受到您正在使用的范例和语言的影响。一些例子(在Haskell中):
- from finance: Composing Contracts
- from word processing: Bridging the Algorithm Gap
- a simple web server: http://lstephen.wordpress.com/2008/02/14/a-simple-haskell-web-server/
- music: http://www.haskell.org/haskore/
来自金融:撰写合同
来自文字处理:缩小算法差距
一个简单的Web服务器:http://lstephen.wordpress.com/2008/02/14/a-simple-haskell-web-server/
#3
0
A flowchart and/or process model/diagram can be used as a functional model for non OO programs. But it still doesn't give the sense of boundaries similar to that of the OO model.
流程图和/或过程模型/图表可以用作非OO程序的功能模型。但它仍然没有给出类似于OO模型的边界感。
#1
6
In fact there is. There is a form of specification for functional languages based on Abstract Data Types called algebraic specification. Their behavior is very similar to that of objects in some ways, however the constructs are logical and mathematical, and are immutable like functional constructs.
实际上有。基于抽象数据类型的函数语言有一种称为代数规范的规范形式。它们的行为在某些方面与对象的行为非常相似,但是构造是逻辑和数学的,并且像函数构造一样是不可变的。
A particular functional specification language that's used in the Algorithms and Data Structures class in the University of Buenos Aires has generators, observers, and additional operations. A generator is an expression that is both an instance and a possible composition of the data type. For example, for a binary tree (ADT bt), we have null nodes, and binary nodes. So we would have the generators:
在布宜诺斯艾利斯大学的算法和数据结构课程中使用的特定功能规范语言具有生成器,观察器和附加操作。生成器是一个表达式,它既是实例又是数据类型的可能组合。例如,对于二叉树(ADT bt),我们有空节点和二进制节点。所以我们会有发电机:
-nil
-bin(left:bt, root: a, right:bt)
Where left is an instance of a bt, the root is a generic value, and right is another bt. So, nil is a valid form of a bt, but bin(bin(nil,1,nil),2,nil) is also valid, representing a binary tree with a root node with a value of 2, a left child node with a value of 1, and a null child right node.
左边是bt的实例,root是泛型值,右边是另一个bt。因此,nil是bt的有效形式,但bin(bin(nil,1,nil),2,nil)也是有效的,表示具有值为2的根节点的二叉树,左子节点值为1,以及null子右节点。
So for a function that say, calculates the number of nodes in a tree, you define an observer of the ADT, and you define a set of axioms which map to each generator. So, for example:
因此,对于一个函数,即计算树中节点的数量,您可以定义ADT的观察者,并定义一组映射到每个生成器的公理。所以,例如:
numberOfNodes(nil) == 0
numberOfNodes(bin(left,x,right))== 1 + numberOfNodes(left) + numberOfNodes(right)
This has the advantage of using recursive definitions of operations, and has the more, formally interesting property that you can use something called structural induction to PROVE that your specification is correct (yes, you demonstrate that your algorithm will produce the proper result).
这具有使用递归操作定义的优点,并且具有更多,正式有趣的属性,您可以使用称为结构归纳的东西来证明您的规范是正确的(是的,您证明您的算法将产生正确的结果)。
This is a fairly academic topic rarely seen outside of academic circles, but it's worth it to get an insight on program design that may change the way you think about algorithms and data structures. The proper bibliography includes:
这是一个在学术界很少见到的相当学术的话题,但是有必要深入了解程序设计,这可能会改变您对算法和数据结构的看法。适当的参考书目包括:
Bernot, G., Bidoit, M., and Knapik, T. 1995. Observational specifications and the indistinguishability assumption. Theor. Comput. Sci. 139, 1-2 (Mar. 1995), 275-314. DOI= http://dx.doi.org/10.1016/0304-3975(94)00017-D
Bernot,G.,Bidoit,M。和Knapik,T。1995.观察规范和不可区分性假设。理论值。 COMPUT。科学。 139,1-2(1995年3月),275-314。 DOI = http://dx.doi.org/10.1016/0304-3975(94)00017-D
Guttag, J. V. and Horning, J. J. 1993. Larch: Languages and Tools for Formal Specification. Springer-Verlag New York, Inc. Abstraction and Specification in Software Development, Barbara Liskov y John Guttag, MIT Press, 1986.
Guttag,J.V。和Horning,J.J.1993。落叶松:正式规范的语言和工具。 Springer-Verlag New York,Inc。软件开发中的抽象和规范,Barbara Liskov和John Guttag,麻省理工学院出版社,1986年。
Fundamentals of Algebraic Specification 1. Equations and Initial Semantics. H. Ehrig y B. Mahr Springer-Verlag, Berlin, Heidelberg, New York, Tokyo, Germany, 1985.
代数规范的基本原理1.方程和初始语义。 H. Ehrig y B. Mahr Springer-Verlag,柏林,海德堡,纽约,东京,德国,1985年。
With corresponding links: http://www.cs.st-andrews.ac.uk/~ifs/Resources/Notes/FormalSpec/AlgebraicSpec.pdf http://nms.lcs.mit.edu/larch/pub/larchBook.ps
使用相应的链接:http://www.cs.st-andrews.ac.uk/~ifs/Resources/Notes/FormalSpec/AlgebraicSpec.pdf http://nms.lcs.mit.edu/larch/pub/larchBook。 PS
It's a heck of an interesting topic.
这是一个有趣的话题。
#2
1
In both OO and FP paradigms, you form your domain model (the problem you're solving) and then create objects in your program to mirror the domain objects. There are some differences, in that how the program objects mirror the domain objects is influenced by the paradigm and langauge you're using. Some examples (in Haskell):
在OO和FP范例中,您构建域模型(您正在解决的问题),然后在程序中创建对象以镜像域对象。存在一些差异,因为程序对象如何镜像域对象受到您正在使用的范例和语言的影响。一些例子(在Haskell中):
- from finance: Composing Contracts
- from word processing: Bridging the Algorithm Gap
- a simple web server: http://lstephen.wordpress.com/2008/02/14/a-simple-haskell-web-server/
- music: http://www.haskell.org/haskore/
来自金融:撰写合同
来自文字处理:缩小算法差距
一个简单的Web服务器:http://lstephen.wordpress.com/2008/02/14/a-simple-haskell-web-server/
#3
0
A flowchart and/or process model/diagram can be used as a functional model for non OO programs. But it still doesn't give the sense of boundaries similar to that of the OO model.
流程图和/或过程模型/图表可以用作非OO程序的功能模型。但它仍然没有给出类似于OO模型的边界感。