Abusing the algebra of algebraic data types - why does this work?

后端 未结 7 1579
失恋的感觉
失恋的感觉 2020-11-28 17:23

The \'algebraic\' expression for algebraic data types looks very suggestive to someone with a background in mathematics. Let me try to explain what I mean.

Having de

相关标签:
7条回答
  • 2020-11-28 17:52

    The Algebra of Communicating Processes (ACP) deals with similar kinds of expressions for processes. It offers addition and multiplication as operators for choice and sequence, with associated neutral elements. Based on these there are operators for other constructs, such as parallelism and disruption. See http://en.wikipedia.org/wiki/Algebra_of_Communicating_Processes. There is also a paper online named "A Brief History of Process Algebra".

    I am working on extending programming languages with ACP. Last April I presented a research paper at Scala Days 2012, available at http://code.google.com/p/subscript/

    At the conference I demonstrated a debugger running a parallel recursive specification of a bag:

    Bag = A; (Bag&a)

    where A and a stand for input and output actions; the semicolon and ampersand stand for sequence and parallelism. See the video at SkillsMatter, reachable from the previous link.

    A bag specification more comparable to

    L = 1 + X•L

    would be

    B = 1 + X&B

    ACP defines parallelism in terms of choice and sequence using axioms; see the Wikipedia article. I wonder what the bag analogy would be for

    L = 1 / (1-X)

    ACP style programming is handy for text parsers and GUI controllers. Specifications such as

    searchCommand = clicked(searchButton) + key(Enter)

    cancelCommand = clicked(cancelButton) + key(Escape)

    may be written down more concisely by making the two refinements "clicked" and "key" implicit (like what Scala allows with functions). Hence we can write:

    searchCommand = searchButton + Enter

    cancelCommand = cancelButton + Escape

    The right hand sides now contains operands that are data, rather than processes. At this level it is not necessary needed to know what implicit refinements will turn these operands into processes; they would not necessarily refine into input actions; output actions would also apply, e.g. in the specification of a test robot.

    Processes get this way data as companions; thus I coin the term "item algebra".

    0 讨论(0)
提交回复
热议问题