首页 > 解决方案 > 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

标签: f#

解决方案


您的类型定义似乎缺少一些东西。类型定义以关键字开头type

这定义了一个类型并打印它的一个实例:

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

在此处查看实际操作:https ://dotnetfiddle.net/Fb0wi5


推荐阅读