小编Mat*_*emp的帖子

模拟F#中的'Any'类型

我想创建一个定义类型的类型:

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#

9
推荐指数
1
解决办法
278
查看次数

标签 统计

f# ×1