let private GetDrives = seq{
let all=System.IO.DriveInfo.GetDrives()
for d in all do
//if(d.IsReady && d.DriveType=System.IO.DriveType.Fixed) then
yield d
}
let valid={'A'..'Z'}
let rec SearchRegistryForInvalidDrive (start:RegistryKey) = seq{
let validDrives=GetDrives |> Seq.map (fun x -> x.Name.Substring(0,1))
let invalidDrives= Seq.toList validDrives |> List.filter(fun x-> not (List.exists2 x b)) //(List.exists is the wrong method I think, but it doesn't compile我遵循了F#: Filter items found in one list from another list,但无法将其应用于我的问题,因为我看到的两种解决方案似乎都不能编译。List.Contains不存在(缺少引用?)而且ListA - ListB也不能编译。
发布于 2012-04-12 05:56:32
open System.IO
let driveLetters = set [ for d in DriveInfo.GetDrives() -> d.Name.[0] ]
let unused = set ['A'..'Z'] - driveLetters发布于 2012-04-12 06:05:45
您的第一个错误是在char和string之间混用,最好从char开始
let all = {'A'..'Z'}
let validDrives = GetDrives |> Seq.map (fun x -> x.Name.[0])现在,无效的驱动器号是那些在all中但不在validDrives中的盘符
let invalidDrives =
all |> Seq.filter (fun c -> validDrives |> List.forall ((<>) c))由于要多次遍历validDrives以检查成员身份,因此在此示例中将其转换为set会更好:
let all = {'A'..'Z'}
let validDrives = GetDrives |> Seq.map (fun x -> x.Name.[0]) |> Set.ofSeq
let invalidDrives = all |> Seq.filter (not << validDrives.Contains)https://stackoverflow.com/questions/10114516
复制相似问题