F# 在字符串数组上使用 List.map

Nic*_*ert 1 lambda f# functional-programming

我正在尝试使用 F# 的 List.map 函数来调用我在数组中的每个字符串上编写的函数。这是我写的函数

(*Takes a string and filters it down to common text characters*)
let filterWord wordToFilter = 
    Regex.Replace(wordToFilter, "[^a-zA-Z0-9/!\'?.-]", "");
Run Code Online (Sandbox Code Playgroud)

这是我称之为的主要方法

(*Main method of the program*)
[<EntryPoint>]
let main argsv =
    let input = File.ReadAllText("Alice in Wonderland.txt"); //Reads all the text into a single string
    let unfilteredWords = input.Split(' ');
    let filteredWords = unfilteredWords |> List.map(fun x -> filterWord(x));
    0;
Run Code Online (Sandbox Code Playgroud)

问题是我在 List.map 调用中遇到语法错误说

Error       Type mismatch. Expecting a
    string [] -> 'a    
but given a
    'b list -> 'c list    
The type 'string []' does not match the type ''a list'  
Run Code Online (Sandbox Code Playgroud)

将 input.split 更改为硬编码的字符串数组修复了错误,因此它与 F# 没有意识到 input.split 的结果可以与 map 函数一起使用,因为它是一个字符串数组。我只是不知道如何更改代码,以便它完成我想要完成的工作。我对 F# 比较陌生,所以我能得到的任何帮助将不胜感激!

Ale*_*nov 5

F# 没有实现 input.split 的结果可以与 map 函数一起使用,因为它是一个字符串数组

List.map适用于lists,因此 F# 意识到结果不能List.map. 改用Array.map(适用于数组)。