我试图在Haskell中拆分列表。据我所知,最简单的方法是使用splitOn
,但此功能需要Data.List.Split
,因此我尝试在Prelude中运行import Data.List.Split
。但是,我收到以下错误:
Could not find module Data.List.Split
但是,只需导入Data.List
即可。
我该怎么做才能解决这个问题?或者,甚至更好:是否有一个简单的内置替代拆分列表?
答案 0 :(得分:7)
答案 1 :(得分:5)
要在任意空格上分割String
(例如,c
为Data.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"]
无需其他导入,因为words
是Prelude
。