zell
zell

Reputation: 10204

Failed attempt to define a record type in F#

I tried to define a F# record. This does not work for me. Any idea? Below I used the interactive mode in Visual Studio.

{x : int};;

 Stopped due to error
 System.Exception: Operation could not be completed due to earlier error
 Unexpected symbol ':' in expression. Expected '}' or other token. at 0,3
 Unmatched '{' at 0,0
 Unexpected symbol ':' in expression. Expected '}' or other token. at 0,3
 Unmatched '{' at 0,0
 Invalid object, sequence or record expression at 0,0
 Invalid record, sequence or computation expression. Sequence expressions should be of the form 'seq { ... }' at 0,0
 Invalid object, sequence or record expression at 0,0
 Invalid record, sequence or computation expression. Sequence expressions should be of the form 'seq { ... }' at 0,0

Upvotes: 0

Views: 99

Answers (1)

Luis Ferrao
Luis Ferrao

Reputation: 1503

Your type definition seems to be missing something. A type definition starts with the keyword type.

This defines a type and prints an instance of it:

type test = {x:int}  // definition
printf "%A" {x = 1}  // example use

See it in action here: https://dotnetfiddle.net/Fb0wi5

Upvotes: 3

Related Questions