0

私は F# を勉強していて、別の人からコードをもらいました。しかし、コードをコンパイルしようとすると、エラーが発生しました。完全なコードは次のようになります。

module touchdev_ast
open FParsec
type Name = string
type Operator =
| Plus | Minus | Slash | Asterisk
| LessOrEqual | Less | Equal | Unequal | GreaterOrEqual | Greater
| Assignment // :=
| And | Or | Not
| Arrow // −>
| Concat // ||

type Parameter = Name (*param name*) * Name (*type qualifier*)

ここ(下の行)でエラー発生!!

type Expression =
public
| Nothing
| Float of float
| Boolean of bool
| Variable of string
| String of string
| BinaryOperation of Operator * Expression * Expression
| FunctionCall of Name (*fun name*) * Expression list (*arguments*)

and Statement =
public
| Block of Statement list
| Expression of Expression
| Assignment of Expression list (*multiple assignment*) * Expression
| If of Expression * Statement (*then*) * Statement option (*else*)
| ForI of Name (*loop variant*) * Expression (*upper bound*) * Statement
| ForEach of Name (*iterator*) * Expression (*collection*) * Expression option (*condition*) * Statement
| While of Expression * Statement
| MetaStatement of Name

and public FunctionType =
Name (*fun name*) * Parameter list option (*input values*)* Parameter list option (*return values*) * Statement

and TopLevel =
public
| MetaDeclaration of Name (*type*) * string (*value*)
| Action of FunctionType
| Event of FunctionType
| Global of Parameter * Statement (*options*)

type CodeEntry =
public
| Namespace of string (* name *) * bool (* singleton *) * CodeEntry list option (* properties *) * string option (* help *)
| Property of string (* name *) * bool (* public *) * Parameter list option (* input *) * Parameter list option (* return values *) * string option (* help *)
| Variable of string (* name *) * bool (* assignable *) * bool (* initialized *) * string (* type *) * string option (* help *)
| BinaryOperator of string (* name *) * string (* type left *) * string (* type right *) * string (* type return *) * string option (* help *)
| Meta of string (* name *) * string (* value *)

バグの修正を手伝ってください!! :D よろしくお願いします!!

4

1 に答える 1

3

F# ではインデントが重要です。そのため、宣言する共用体型ごとにケース宣言をインデントする必要があります。publicまた、ケースはデフォルトで公開されるため、修飾子は必要ありません(ただし、これはバグとは関係ありません)。

module touchdev_ast
open FParsec
type Name = string
type Operator =
    | Plus | Minus | Slash | Asterisk
    | LessOrEqual | Less | Equal | Unequal | GreaterOrEqual | Greater
    | Assignment // :=
    | And | Or | Not
    | Arrow // −>
    | Concat // ||

type Parameter = Name (*param name*) * Name (*type qualifier*)

type Expression =
    | Nothing
    | Float of float
    | Boolean of bool
    | Variable of string
    | String of string
    | BinaryOperation of Operator * Expression * Expression
    | FunctionCall of Name (*fun name*) * Expression list (*arguments*)

and Statement =
    | Block of Statement list
    | Expression of Expression
    | Assignment of Expression list (*multiple assignment*) * Expression
    | If of Expression * Statement (*then*) * Statement option (*else*)
    | ForI of Name (*loop variant*) * Expression (*upper bound*) * Statement
    | ForEach of Name (*iterator*) * Expression (*collection*) * Expression option (*condition*) * Statement
    | While of Expression * Statement
    | MetaStatement of Name

and public FunctionType =
    Name (*fun name*) * Parameter list option (*input values*)* Parameter list option (*return values*) * Statement

and TopLevel =
    | MetaDeclaration of Name (*type*) * string (*value*)
    | Action of FunctionType
    | Event of FunctionType
    | Global of Parameter * Statement (*options*)

type CodeEntry =
    | Namespace of string (* name *) * bool (* singleton *) * CodeEntry list option (* properties *) * string option (* help *)
    | Property of string (* name *) * bool (* public *) * Parameter list option (* input *) * Parameter list option (* return values *) * string option (* help *)
    | Variable of string (* name *) * bool (* assignable *) * bool (* initialized *) * string (* type *) * string option (* help *)
    | BinaryOperator of string (* name *) * string (* type left *) * string (* type right *) * string (* type return *) * string option (* help *)
    | Meta of string (* name *) * string (* value *)
于 2013-01-02T13:52:34.740 に答える