Haskell:找不到模块"Data.List.Split" [英] Haskell: Could not find module `Data.List.Split'
问题描述
我正在尝试在Haskell中拆分列表.据我所知,最简单的方法是使用splitOn
,但是此功能需要Data.List.Split
,因此我尝试在Prelude中运行import Data.List.Split
.但是,出现以下错误:
I'm trying to split a list in Haskell. As to my knowledge, the easiest way to do this is with splitOn
, but this function requires Data.List.Split
, so I tried to run import Data.List.Split
in Prelude. However, I got the following error:
Could not find module Data.List.Split
仅导入Data.List
即可.
我该怎么做才能解决这个问题?或者,甚至更好:拆分列表是否有一种简单的内置替代方法?
What could I do to solve this? Or, even better: is there an easy, built-in alternative to split lists?
推荐答案
要在任意空白处分割String
(例如,任何Data.Char.isSpace c
为True
的Char c
),请使用words
:
To split a String
on arbitrary white space (e.g. any Char c
where Data.Char.isSpace c
is True
), use 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"]
由于 words
是Prelude
的一部分.
这篇关于Haskell:找不到模块"Data.List.Split"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!