请输入您要查询的百科知识:

 

词条 Mogensen–Scott encoding
释义

  1. History

  2. Discussion

  3. Definition

     Scott encoding   Mogensen–Scott encoding  

  4. Comparison to the Church encoding

  5. Type definitions

  6. See also

  7. Notes

  8. References

In computer science, Scott encoding is a way to represent (recursive) data types in the lambda calculus. Church encoding performs a similar function. The data and operators form a mathematical structure which is embedded in the lambda calculus.

Whereas Church encoding starts with representations of the basic data types, and builds up from it, Scott encoding starts from the simplest method to compose algebraic data types.

Mogensen–Scott encoding extends and slightly modifies Scott encoding by applying the encoding to Metaprogramming. This encoding allows the representation of lambda calculus terms, as data, to be operated on by a meta program.

History

Scott encoding appears first in a set of unpublished lecture notes by Dana Scott. Torben Mogensen later extended Scott encoding for the encoding of Lambda terms as data.[1]

Discussion

Lambda calculus allows data to be stored as parameters to a function that does not yet have all the parameters required for application. For example,

May be thought of as a record or struct where the fields have been initialized with the values . These values may then be accessed by applying the term to a function f. This reduces to,

c may represent a constructor for an algebraic data type in functional languages such as Haskell. Now suppose there are N constructors, each with arguments;

Each constructor selects a different function from the function parameters . This provides branching in the process flow, based on the constructor. Each constructor may have a different arity (number of parameters). If the constructors have no parameters then the set of constructors acts like an enum; a type with a fixed number of values. If the constructors have parameters, recursive data structures may be constructed.

Definition

Let D be a datatype with N constructors, , such that constructor has arity .

Scott encoding

The Scott encoding of constructor of the data type D is

Mogensen–Scott encoding

Mogensen extends Scott encoding to encode any untyped lambda term as data. This allows a lambda term to be represented as data, within a Lambda calculus meta program. The meta function mse converts a lambda term into the corresponding data representation of the lambda term;

The "lambda term" is represented as a tagged union with three cases:

  • Constructor a - a variable (arity 1, not recursive)
  • Constructor b - function application (arity 2, recursive in both arguments),
  • Constructor c - lambda-abstraction (arity 1, recursive).

For example,

Comparison to the Church encoding

The Scott encoding coincides with the Church encoding for booleans. Church encoding of pairs may be generalized to arbitrary data types by encoding of D above as{{Citation needed|date=February 2018}}

compare this to the Mogensen Scott encoding,

With this generalization, the Scott and Church encodings coincide on all enumerated datatypes (such as the boolean datatype) because each constructor is a constant (no parameters).

Type definitions

Church-encoded data and operations on them are typable in system F, but Scott-encoded data and operations are not obviously typable in system F. Universal as well as recursive types appear to be required,[2] and since strong normalization does not hold for recursively typed lambda calculus{{Citation needed|reason=System D sub has recursive self-types and yet remains strongly normalizing, thus, this ought to have a citation, even if it seems obvious.|date=July 2018}}, termination of programs manipulating Scott-encoded data cannot be established by determining well-typedness of such programs.

See also

  • Church encoding
  • System F
  • Lambda cube

Notes

1. ^ {{ cite journal|last=Mogensen|first=Torben|title=Efficient Self-Interpretation in Lambda Calculus|journal=Journal of Functional Programming|year=1994|volume=2|pages=345-364}}
2. ^See the note "Types for the Scott numerals" by Martín Abadi, Luca Cardelli and Gordon Plotkin (February 18, 1993).

References

  • Directly Reflective Meta-Programming
  • Torben Mogensen (1992). Efficient Self-Interpretation in Lambda Calculus. Journal of Functional Programming.
{{DEFAULTSORT:Mogensen-Scott encoding}}

1 : Lambda calculus

随便看

 

开放百科全书收录14589846条英语、德语、日语等多语种百科知识,基本涵盖了大多数领域的百科知识,是一部内容自由、开放的电子版国际百科全书。

 

Copyright © 2023 OENC.NET All Rights Reserved
京ICP备2021023879号 更新时间:2024/11/12 4:36:51