JSong
JSong

Reputation: 360

Error message "to define a type, one or more ..."

I am studying F#, and I got some code from another person. But when I tried to compile the code, there was an error. The full code is like below:

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*)

here(the line below) an error occurs!!

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 *)

Please help me fix the bug!! :D Thanks in advance!!

Upvotes: 0

Views: 84

Answers (1)

Jack P.
Jack P.

Reputation: 11525

Indentation is important in F# -- so you need to indent the case declarations for each union type you declare. Also, you don't need the public modifiers, as the cases will be public by default (this isn't related to your bug though).

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 *)

Upvotes: 3

Related Questions