【发布时间】:2021-12-30 10:15:37
【问题描述】:
我正在尝试从一个具有多重递归的列表中获取特定值,所以我有:
type PowerSystem =
| System of string * int
| Junction of string * List<PowerSystem>
let Starship =
Junction("Core",
[
Junction("Users",
[
System("Main Computer",-10);
System("Library Computer",-10);
Junction("Defence",)]
let rec JunctionPath (pSystem:PowerSystem) =
match pSystem with
| Junction(name,aList) -> SplitList2 aList
| System(name,aNumber) -> [name]
and SplitList2 list =
match list with
| [] -> printfn "%A" []
| head::tail -> printfn "%A" List.filter (fun e->e="Port Phasers" (JunctionPath head)@(SplitList2 tail))
JunctionPath Starship
我收到错误 FS0001:类型“a -> 字符串列表”与类型“单元”不匹配
我想在系统调用主计算机时获取连接的名称,但我不能调用其他函数。我尝试以不同的方式获得这些值,但我找不到方法。提前致谢
【问题讨论】:
-
顺便说一句,您错过了
let Startship = ...中的右方括号
标签: f# f#-interactive