4th Street Bar Hive-Bar

Hive-Bar Powered by Hive beta-fdb5b5b

Community post

Nominal Typing VS Structural Typing ( + Duck Typing)

Type System 3가지

  1. Nominal Type System
  2. Structural Type System
  3. Duck Typing

Nominal Type System

C++, Java 에서 만날 수 있는 타입 시스템이다. 우리가 기본적으로 알고 있듯이 이름이 같아야 한다.

class A {
    int a;
}

class B {
    int a;
}

A a = new B(); // ERROR!!!

Structural Type System

반면에 Structural typing 을 하는 언어들은 위의 케이스가 가능하다. 왜냐면 클래스 A 와 B의 구조가 같기 때문이다.

Typescript 나 Ocaml 같은 언어가 Structural typing 을 쓴다.

나는 이걸 보고 duck typing 과 뭐가 다르지? 라는 의문이 들었다.

Duck Typing

duck typing 은 static type system 이 아닌, dynamic 언어에서의 개념이다. 따라서 Structural typing 과는 약간 다르다.

타입 자체가 존재하지 않는 Javascript 나 Ruby 같은 것이 duck typing 이라고 볼 수 있다.

2 upvotes $0.78

Replies (3)

Review before signing

Posting as . Signing with . Keychain permission: Posting. Hive Keychain will ask you to approve this action next.


  
Technical details

Operation fingerprint: