Share
VIDEOS 1 TO 50
The Structural Theory of Pure Type Systems
The Structural Theory of Pure Type Systems
Published: 2016/07/27
Channel: Microsoft Research
Scala
Scala's Type System: a tutorial
Published: 2012/04/01
Channel: Ben Hutchison
A Type System From Scratch – Robert Widmann
A Type System From Scratch – Robert Widmann
Published: 2017/04/24
Channel: Functional Swift
Lambda Days - Konrad Malawski - Types of Types... in Scala
Lambda Days - Konrad Malawski - Types of Types... in Scala
Published: 2014/04/22
Channel: Erlang Solutions
TypeScript Structural Typing
TypeScript Structural Typing
Published: 2015/08/05
Channel: life michael
"Aggregator: MapReduce in the type system" by Dan Frank
"Aggregator: MapReduce in the type system" by Dan Frank
Published: 2015/09/28
Channel: Strange Loop
Types of Neurons - Structural and Functional Classes
Types of Neurons - Structural and Functional Classes
Published: 2016/03/08
Channel: Justin Siebert
Business Studies - Organisation Structure: Business Exam Tips
Business Studies - Organisation Structure: Business Exam Tips
Published: 2014/06/02
Channel: Revision App - Student Blog
CSE 340 S16: 3-30-16 "Hindley-Milner Type Inference pt. 1"
CSE 340 S16: 3-30-16 "Hindley-Milner Type Inference pt. 1"
Published: 2016/03/31
Channel: Adam Doupé
Neurons or nerve cells - Structure function and types of neurons | Human Anatomy | 3D Biology
Neurons or nerve cells - Structure function and types of neurons | Human Anatomy | 3D Biology
Published: 2013/04/27
Channel: Elearnin
Philly ETE 2016 #12 - Academese to English: A Practical Tour of Scala’s Type System - Heather Miller
Philly ETE 2016 #12 - Academese to English: A Practical Tour of Scala’s Type System - Heather Miller
Published: 2016/05/10
Channel: ChariotSolutions
An introduction to type systems
An introduction to type systems
Published: 2017/03/26
Channel: Ralf Laemmel
Virus structure and classification | Cells | MCAT | Khan Academy
Virus structure and classification | Cells | MCAT | Khan Academy
Published: 2015/01/21
Channel: khanacademymedicine
CSE 340 11-16-15 Office Hours "Structural Equivalence"
CSE 340 11-16-15 Office Hours "Structural Equivalence"
Published: 2015/11/17
Channel: Adam Doupé
CSE 340 11-16-15 Office Hours "Type Equivalence"
CSE 340 11-16-15 Office Hours "Type Equivalence"
Published: 2015/11/17
Channel: Adam Doupé
Structural Joints in Precast Concrete
Structural Joints in Precast Concrete
Published: 2017/02/07
Channel: JSP
Placing Beam Systems and Structural Floors
Placing Beam Systems and Structural Floors
Published: 2016/04/18
Channel: Autodesk Building Solutions
Structure of the Court System: Crash Course Government and Politics #19
Structure of the Court System: Crash Course Government and Politics #19
Published: 2015/06/05
Channel: CrashCourse
Microbiology - Viruses (Structure, Types and Bacteriophage Replication)
Microbiology - Viruses (Structure, Types and Bacteriophage Replication)
Published: 2013/08/06
Channel: Armando Hasudungan
Type Systems I - Vladimir Voevodsky
Type Systems I - Vladimir Voevodsky
Published: 2016/08/17
Channel: Institute for Advanced Study
TIAP Garrett Morris - Substructural Types with Class
TIAP Garrett Morris - Substructural Types with Class
Published: 2015/05/15
Channel: SoC Dundee
Cody Roux - Pure Type Systems
Cody Roux - Pure Type Systems
Published: 2015/03/29
Channel: Boston Haskell
What is organizational structure?
What is organizational structure?
Published: 2016/02/11
Channel: BusinessDictionary
The Nervous System, Part 1: Crash Course A&P #8
The Nervous System, Part 1: Crash Course A&P #8
Published: 2015/02/23
Channel: CrashCourse
Structural Steel Connections
Structural Steel Connections
Published: 2013/03/11
Channel: Tom Rogers
Economic Systems and Macroeconomics: Crash Course Economics #3
Economic Systems and Macroeconomics: Crash Course Economics #3
Published: 2015/07/30
Channel: CrashCourse
CSE 340 F16: 10-19-16 "Types Pt. 4 and Hindley Milner Pt. 1"
CSE 340 F16: 10-19-16 "Types Pt. 4 and Hindley Milner Pt. 1"
Published: 2016/10/19
Channel: Adam Doupé
Explanation-System calls and System call types in operating system
Explanation-System calls and System call types in operating system
Published: 2017/07/13
Channel: Last moment Learning
Conor McBride - Worldly Type Systems
Conor McBride - Worldly Type Systems
Published: 2016/05/04
Channel: Sophie Taylor
Type Systems - Vladimir Voevodsky
Type Systems - Vladimir Voevodsky
Published: 2016/08/18
Channel: Institute for Advanced Study
The Gradualizer: A Methodology and Algorithm for Generating Gradual Type Systems
The Gradualizer: A Methodology and Algorithm for Generating Gradual Type Systems
Published: 2016/04/05
Channel: Ras Bodik
ARE 4.0 Structural Systems (SS): Multiple Choice
ARE 4.0 Structural Systems (SS): Multiple Choice
Published: 2015/02/18
Channel: NCARB
The Typeclass Pattern - An Alternative to Inheritance
The Typeclass Pattern - An Alternative to Inheritance
Published: 2012/03/28
Channel: InfoQ
How to understand power - Eric Liu
How to understand power - Eric Liu
Published: 2014/11/04
Channel: TED-Ed
NEET BIO - Neuron: structural and functional unit of neural system
NEET BIO - Neuron: structural and functional unit of neural system
Published: 2013/11/20
Channel: XLClasses
Substructural Type Systems and Concurrent Programming 4 - Frank Pfenning - OPLSS 2017
Substructural Type Systems and Concurrent Programming 4 - Frank Pfenning - OPLSS 2017
Published: 2017/06/30
Channel: OPLSS
structural classification of neurons
structural classification of neurons
Published: 2011/08/12
Channel: Ren Hartung
Types In Julia (Inspecting  Abstract and Concrete Types)
Types In Julia (Inspecting Abstract and Concrete Types)
Published: 2017/07/03
Channel: J-Secur1ty
Glial Cells - Neuroanatomy Basics - Anatomy Tutorial
Glial Cells - Neuroanatomy Basics - Anatomy Tutorial
Published: 2014/05/19
Channel: AnatomyZone
Type Systems II- Vladimir Voevodsky
Type Systems II- Vladimir Voevodsky
Published: 2016/08/17
Channel: Institute for Advanced Study
Structural Geology segment 2 - Folding
Structural Geology segment 2 - Folding
Published: 2012/09/12
Channel: Aida Awad
Plant Structure
Plant Structure
Published: 2012/04/21
Channel: Bozeman Science
ZuriHac 2016: Generic (and type-level) Programming with Generics-sop
ZuriHac 2016: Generic (and type-level) Programming with Generics-sop
Published: 2016/09/06
Channel: GoogleTechTalks
Stick Curtain Wall System
Stick Curtain Wall System
Published: 2012/03/22
Channel: Curtain Wall Story
Revit Structure Lesson 2: Create Structural Wall Types in Revit 2017
Revit Structure Lesson 2: Create Structural Wall Types in Revit 2017
Published: 2016/11/20
Channel: Learning With Rich
Cerebral cortex | Organ Systems | MCAT | Khan Academy
Cerebral cortex | Organ Systems | MCAT | Khan Academy
Published: 2014/04/25
Channel: khanacademymedicine
Scala Courses by Klika Tech, Class #5 (RU)
Scala Courses by Klika Tech, Class #5 (RU)
Published: 2016/09/05
Channel: Klika Tech, LLC
Microbiology - Bacteria (Structure)
Microbiology - Bacteria (Structure)
Published: 2013/02/19
Channel: Armando Hasudungan
Biology Structural Organization Animals part 3 (Types Animal tissues: Epithelial) CBSE class 11 XI
Biology Structural Organization Animals part 3 (Types Animal tissues: Epithelial) CBSE class 11 XI
Published: 2014/12/12
Channel: ExamFear Education
Damas-Milner type system - Haskell.SG
Damas-Milner type system - Haskell.SG
Published: 2015/07/01
Channel: Engineers.SG
NEXT
GO TO RESULTS [51 .. 100]

WIKIPEDIA ARTICLE

From Wikipedia, the free encyclopedia
Jump to: navigation, search

A structural type system (or property-based type system) is a major class of type system, in which type compatibility and equivalence are determined by the type's actual structure or definition, and not by other characteristics such as its name or place of declaration. Structural systems are used to determine if types are equivalent and whether a type is a subtype of another. It contrasts with nominative systems, where comparisons are based on the names of the types or explicit declarations, and duck typing, in which only the part of the structure accessed at runtime is checked for compatibility.

Description[edit]

In structural typing, an element is considered to be compatible with another if, for each feature within the second element's type, a corresponding and identical feature exists in the first element's type. Some languages may differ on the details, such as whether the features must match in name. This definition is not symmetric, and includes subtype compatibility. Two types are considered to be identical if each is compatible with the other.

For example, OCaml uses structural typing on methods for compatibility of object types. Go uses structural typing on methods to determine compatibility of a type with an interface. C++ template functions exhibit structural typing on type arguments. Haxe uses structural typing, but classes are not structurally subtyped.

In languages which support subtype polymorphism, a similar dichotomy can be formed based on how the subtype relationship is defined. One type is a subtype of another if and only if it contains all the features of the base type, or subtypes thereof. The subtype may contain added features, such as members not present in the base type, or stronger invariants.

A distinction exists between structural substitution for inferred and non-inferred polymorphism. Some languages, such as Haskell, do not substitute structurally in the case where an expected type is declared (i.e., not inferred), e.g., only substitute for functions that are signature-based polymorphic via type inference.[1] Then it is not possible to accidentally subtype a non-inferred type, although it may still be possible to provide an explicit conversion to a non-inferred type, which is invoked implicitly.

Structural subtyping is arguably more flexible than nominative subtyping, as it permits the creation of ad hoc types and protocols; in particular, it permits creation of a type which is a supertype of an existing type, without modifying the definition of the latter. However, this may not be desirable where the programmer wishes to create closed abstractions.

A pitfall of structural typing versus nominative typing is that two separately defined types intended for different purposes, but accidentally holding the same properties (e.g. both composed of a pair of integers), could be considered the same type by the type system, simply because they happen to have identical structure. One way this can be avoided is by creating one algebraic data type for each use.

In 1990, Cook, et al., proved that inheritance is not subtyping in structurally-typed OO languages.[2]

Example[edit]

Objects in OCaml are structurally typed by the names and types of their methods.

Objects can be created directly (immediate objects) without going through a nominative class. Classes only serve as functions for creating objects.

 # let x =
     object
       val mutable x = 5
       method get_x = x
       method set_x y = x <- y
     end;;
 val x : < get_x : int; set_x : int -> unit > = <obj>

Here the OCaml interactive runtime prints out the inferred type of the object for convenience. Its type (< get_x : int; set_x : int -> unit >) is defined only by its methods. In other words, the type of x is defined by the method types "get_x : int" and "set_x : int -> unit" rather than by any name.[3]

To define another object, which has the same methods and types of methods:

 # let y =
     object
       method get_x = 2
       method set_x y = Printf.printf "%d\n" y
     end;;
 val y : < get_x : int; set_x : int -> unit > = <obj>

OCaml considers them the same type. For example, the equality operator is typed to only take two values of the same type:

 # x = y;;
 - : bool = false

So they must be the same type, or else this wouldn't even type-check. This shows that equivalence of types is structural.

One can define a function that invokes a method:

 # let set_to_10 a = a#set_x 10;;
 val set_to_10 : < set_x : int -> 'a; .. > -> 'a = <fun>

The inferred type for the first argument (< set_x : int -> 'a; .. >) is interesting. The .. means that the first argument can be any object which has a "set_x" method, which takes an int as argument.

So it can be used on object x:

 # set_to_10 x;;
 - : unit = ()

Another object can be made that happens to have that method and method type; the other methods are irrelevant:

 # let z =
     object
       method blahblah = 2.5
       method set_x y = Printf.printf "%d\n" y
     end;;
 val z : < blahblah : float; set_x : int -> unit > = <obj>

The "set_to_10" function also works on it:

 # set_to_10 z;;
 10
 - : unit = ()

This shows that compatibility for things like method invocation is determined by structure.

Let us define a type synonym for objects with only a "get_x" method and no other methods:

 # type simpler_obj = < get_x : int >;;
 type simpler_obj = < get_x : int >

The object x is not of this type; but structurally, x is of a subtype of this type, since x contains a superset of its methods. So x can be coerced to this type:

 # (x :> simpler_obj);;
 - : simpler_obj = <obj>
 # (x :> simpler_obj)#get_x;;
 - : int = 10

But not object z, because it is not a structural subtype:

 # (z :> simpler_obj);;
 This expression cannot be coerced to type simpler_obj = < get_x : int >;
 it has type < blahblah : float; set_x : int -> unit > but is here used with type
   < get_x : int; .. >
 The first object type has no method get_x

This shows that compatibility for widening coercions are structural.

References[edit]

  1. ^ "Signature-based polymorphism". 
  2. ^ Cook, W.R.; Hill, W.L.; Canning, P.S. (January 1990). "Inheritance is not subtyping". Proceedings of the Seventeenth Annual ACM Symposium on Principles of Programming Languages. San Francisco, California: 125–135. doi:10.1145/96709.96721. 
  3. ^ "Object types". 

External links[edit]

Disclaimer

None of the audio/visual content is hosted on this site. All media is embedded from other sites such as GoogleVideo, Wikipedia, YouTube etc. Therefore, this site has no control over the copyright issues of the streaming media.

All issues concerning copyright violations should be aimed at the sites hosting the material. This site does not host any of the streaming media and the owner has not uploaded any of the material to the video hosting servers. Anyone can find the same content on Google Video or YouTube by themselves.

The owner of this site cannot know which documentaries are in public domain, which has been uploaded to e.g. YouTube by the owner and which has been uploaded without permission. The copyright owner must contact the source if he wants his material off the Internet completely.

Powered by YouTube
Wikipedia content is licensed under the GFDL and (CC) license