Haskell:找不到模块"Data.List.Split" [英] Haskell: Could not find module `Data.List.Split'

查看:171
本文介绍了Haskell:找不到模块"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 cTrue的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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆