Haskell:找不到模块`Data.List.Split'

时间:2015-12-09 09:31:21

标签: haskell

我试图在Haskell中拆分列表。据我所知,最简单的方法是使用splitOn,但此功能需要Data.List.Split,因此我尝试在Prelude中运行import Data.List.Split。但是,我收到以下错误:

Could not find module Data.List.Split

但是,只需导入Data.List即可。

我该怎么做才能解决这个问题?或者,甚至更好:是否有一个简单的内置替代拆分列表?

2 个答案:

答案 0 :(得分:7)

Data.List.Split不在base我认为你必须安装split

更新

在评论中澄清后,只需要在空格上分割 - 使用words / lines来满足您的需求 - 另请参阅@ Zeta的答案。

答案 1 :(得分:5)

要在任意空格上分割String(例如,cData.Char.isSpace c的任何字符True),请使用words

-- words :: String -> [String]
ghci> words "Hello World, I'm a string \n example   \r\t with white space"
["Hello","World,","I'm","a","string","example","with","white","space"]

无需其他导入,因为wordsPrelude

的一部分