Fable: ๋‹จ์œ„ ์œ ํ˜•์˜ ๋‹จ์ผ ํ•„๋“œ๊ฐ€ ์žˆ๋Š” ๋ ˆ์ฝ”๋“œ๋Š” ๊นจ์ง„ โ€‹โ€‹์ƒ์„ฑ์ž๋ฅผ ์ƒ์„ฑํ•ฉ๋‹ˆ๋‹ค.

์— ๋งŒ๋“  2018๋…„ 09์›” 06์ผ  ยท  3์ฝ”๋ฉ˜ํŠธ  ยท  ์ถœ์ฒ˜: fable-compiler/Fable

์„ค๋ช…

unit ์œ ํ˜•์˜ ๋‹จ์ผ ์š”์†Œ ๋ ˆ์ฝ”๋“œ๋ฅผ ์ƒ์„ฑํ•  ๋•Œ ์ƒ์„ฑ๋œ ํด๋ž˜์Šค ์ƒ์„ฑ์ž๋Š” ์œ ํšจํ•˜์ง€ ์•Š์œผ๋ฉฐ ๋Ÿฐํƒ€์ž„์— ReferenceError๋ฅผ ์ƒ์„ฑํ•ฉ๋‹ˆ๋‹ค.

์žฌํ˜„ ์ฝ”๋“œ

์šฐํ™” REPL ์ƒ˜ํ”Œ...

type Test = {
    Abc: unit
}

printfn "%A" <| { Abc = () }

์ƒ์‚ฐ:

import { setType } from "fable-core/Symbol";
import _Symbol from "fable-core/Symbol";
import { compareRecords, equalsRecords, Unit } from "fable-core/Util";
import { printf, toConsole } from "fable-core/String";
export class Test {
  constructor() {
    this.Abc = abc;
  }

  [_Symbol.reflection]() {
    return {
      type: "Test.Test",
      interfaces: ["FSharpRecord", "System.IEquatable", "System.IComparable"],
      properties: {
        Abc: Unit
      }
    };
  }

  Equals(other) {
    return equalsRecords(this, other);
  }

  CompareTo(other) {
    return compareRecords(this, other) | 0;
  }

}
setType("Test.Test", Test);
toConsole(printf("%A"))(new Test());

์ƒ์„ฑ์ž์—์„œ ํ•„๋“œ๋ฅผ ์ดˆ๊ธฐํ™”ํ•˜๋Š” ๋ฐ ์‚ฌ์šฉํ•˜๋Š” abc ์ธ์ˆ˜๊ฐ€ ๋ˆ„๋ฝ๋˜์—ˆ์Šต๋‹ˆ๋‹ค.

type Test = {
    Abc: unit
    Xyz: int
}

printfn "%A" <| { Abc = (); Xyz = 123 }

์ƒ์‚ฐ:

import { setType } from "fable-core/Symbol";
import _Symbol from "fable-core/Symbol";
import { compareRecords, equalsRecords, Unit } from "fable-core/Util";
import { printf, toConsole } from "fable-core/String";
export class Test {
  constructor(abc, xyz) {
    this.Abc = abc;
    this.Xyz = xyz | 0;
  }

  [_Symbol.reflection]() {
    return {
      type: "Test.Test",
      interfaces: ["FSharpRecord", "System.IEquatable", "System.IComparable"],
      properties: {
        Abc: Unit,
        Xyz: "number"
      }
    };
  }

  Equals(other) {
    return equalsRecords(this, other);
  }

  CompareTo(other) {
    return compareRecords(this, other) | 0;
  }

}
setType("Test.Test", Test);
toConsole(printf("%A"))(new Test(null, 123));

๋”ฐ๋ผ์„œ ๋ ˆ์ฝ”๋“œ์— ๋‹ค๋ฅธ ํ•„๋“œ๊ฐ€ ์ถ”๊ฐ€๋˜๋ฉด ์ƒ์„ฑ์ž๊ฐ€ ์˜ฌ๋ฐ”๋ฅด๊ฒŒ ํ˜•์„ฑ๋ฉ๋‹ˆ๋‹ค.

๊ด€๋ จ ์ •๋ณด

REPL์„ ํ†ตํ•ด์„œ๋„ ๊ด€์ฐฐ๋œ ์ตœ์‹  ๋ชจ๋“  ๊ฒƒ(Fable 1).

๊ฐ€์žฅ ์œ ์šฉํ•œ ๋Œ“๊ธ€

Fable2์—์„œ ๊ดœ์ฐฎ์•„ ๋ณด์ธ๋‹ค

์—ฌ๊ธฐ Repl์ด ์ž‘๋™ ํ•ฉ๋‹ˆ๋‹ค.

์ฝ˜์†”: {Abc = null}

๋ชจ๋“  3 ๋Œ“๊ธ€

Fable2์—์„œ ๊ดœ์ฐฎ์•„ ๋ณด์ธ๋‹ค

์—ฌ๊ธฐ Repl์ด ์ž‘๋™ ํ•ฉ๋‹ˆ๋‹ค.

์ฝ˜์†”: {Abc = null}

@xdaDaveShaw๋ฅผ ํ™•์ธํ•ด์ฃผ์…”์„œ ๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค! Fable 2 @SirUppyPancakes์—์„œ ์ž‘๋™ํ•˜๋Š” ๊ฒฝ์šฐ ์ด ๋ฌธ์ œ๋ฅผ ๋‹ซ์•„๋„ ๋ ๊นŒ์š”?

์˜ˆ, ํ™•์‹คํžˆ!

์ด ํŽ˜์ด์ง€๊ฐ€ ๋„์›€์ด ๋˜์—ˆ๋‚˜์š”?
0 / 5 - 0 ๋“ฑ๊ธ‰

๊ด€๋ จ ๋ฌธ์ œ

MangelMaxime picture MangelMaxime  ยท  3์ฝ”๋ฉ˜ํŠธ

stkb picture stkb  ยท  3์ฝ”๋ฉ˜ํŠธ

alfonsogarciacaro picture alfonsogarciacaro  ยท  3์ฝ”๋ฉ˜ํŠธ

alfonsogarciacaro picture alfonsogarciacaro  ยท  3์ฝ”๋ฉ˜ํŠธ

alfonsogarciacaro picture alfonsogarciacaro  ยท  3์ฝ”๋ฉ˜ํŠธ