相关疑难解决方法(0)

F#将一个有区别的联合转换为字符串

我正在尝试将一个有区别的联合转换为字符串,但我不明白为什么这个代码不起作用.

type 'a sampleType =
 | A of 'a
 | B of 'a

let sampleTypeToString x =
 match x with
 | A (value) -> string value
 | B (value) -> string value
Run Code Online (Sandbox Code Playgroud)

这是fsharp交互输出

sampleTypeToString A(2);;
 Stopped due to error
 System.Exception: Operation could not be completed due to earlier error
 Successive arguments should be separated by spaces or tupled, and arguments involving function or method applications should be parenthesized at 3,19
 This expression was expected to have type
     'obj'    
 but here …
Run Code Online (Sandbox Code Playgroud)

f# discriminated-union f#-interactive

3
推荐指数
1
解决办法
789
查看次数

标签 统计

discriminated-union ×1

f# ×1

f#-interactive ×1