상위 질문
타임라인
채팅
관점

Haxe

위키백과, 무료 백과사전

Remove ads

Haxe는 각기 다른 수많은 컴퓨팅 플랫폼을 대상으로 하나의 코드 기반으로 애플리케이션소스 코드를 생성할 수 있는, 고급 크로스 플랫폼 멀티 패러다임 프로그래밍 언어이자 컴파일러이다.[2][3][4][5] GNU GPL 버전 2로 배포되는 자유-오픈 소스 소프트웨어이며 표준 라이브러리의 경우 MIT 라이선스를 따른다.

간략 정보 개발자, 발표일 ...
Remove ads

언어

요약
관점

Haxe는 객체 지향 프로그래밍, 제네릭 프로그래밍, 다양한 함수형 프로그래밍 구조체를 지원하는 범용 목적의 언어이다. 반복, 예외 처리, 코드 반영 등의 기능들 또한 이 언어와 라이브러리의 내장 기능들이다.[6]

클래스

interface ICreature {
    public var birth:Date;
    public var name:String;

    public function age():Int;
}

class Fly implements ICreature {
    public var birth:Date;
    public var name:String;

    public function age():Int return Date.now().getFullYear() - birth.getFullYear();
}

열거형

enum Color {
    red;
    green;
    blue;
    rgb( r : Int, g : Int, b : Int );
}

class Colors {
    static function toInt ( c : Color ) : Int {
        return switch ( c ) {
            case red: 0xFF0000;
            case green: 0x00FF00;
            case blue: 0x0000FF;
            case rgb(r, g, b): (r << 16) | (g << 8) | b;
        }
    }
    static function validCalls() {
        var redint = toInt(Color.red);
        var rgbint = toInt(Color.rgb(100, 100, 100));
    }
}

익명(무명) 형식

typedef AliasForAnon = { a:Int, b:String, c:Float->Void };

함수형

typedef F = Int->String->Float;

typedef F2 = Int->String->F;
typedef F3 = Int->String->(Int->String->Float);

추상형

abstract Kilometer(Float) {
    public function new(v:Float) this = v;
}

abstract Mile(Float) {
    public function new(v:Float) this = v;
    @:to public inline function toKilometer():Kilometer return (new Kilometer(this / 0.62137));
}

class Test {
  static var km:Kilometer;
  static function main(){
    var one100Miles = new Mile(100);
    km = one100Miles;

    trace(km); // 160.935
  }
}

구조적 타이핑

class FooBar {

   public var foo:Int;
   public var bar:String;

   public function new(){ foo=1; bar="2";}

   function anyFooBar(v:{foo:Int,bar:String}) trace(v.foo);

   static function test(){
        var fb = new FooBar();
        fb.anyFooBar(fb);
        fb.anyFooBar({foo:123,bar:"456"});
   }
}
Remove ads

같이 보기

각주

외부 링크

Loading related searches...

Wikiwand - on

Seamless Wikipedia browsing. On steroids.

Remove ads