我想创建一个定义类型的类型:
type LeftRight<'left, 'right> = {
Left : 'left list
Right : 'right list
}
Run Code Online (Sandbox Code Playgroud)
和几个功能:
let makeLeft xs = { Left = xs; Right = [] }
let makeRight ys = { Left = []; Right = ys }
Run Code Online (Sandbox Code Playgroud)
我想提供一个'组合器'功能:
let combine l r = { Left = l.Left @ r.Left; Right = l.Right @ r.Right }
Run Code Online (Sandbox Code Playgroud)
当我尝试做某事时,我(显然!)因为我的价值是通用的而得到问题:
let aaa = makeLeft [1;2;3]
// Value restriction. The value 'aaa' has been inferred to have generic type
// val aaa …Run Code Online (Sandbox Code Playgroud) f# ×1