Haskell: Could not find module `Data.List.Split'

非 Y 不嫁゛ 提交于 2020-02-03 05:16:41

问题


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

Simply importing Data.List does work, however.

What could I do to solve this? Or, even better: is there an easy, built-in alternative to split lists?


回答1:


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"]

No need for additional imports, since words is part of the Prelude.




回答2:


Data.List.Split is not in the base I think you'll have to install split

Update

after the clarification in the comments that only splitting on whitespace is required - use words/lines to your need - see also @Zeta's answer.



来源:https://stackoverflow.com/questions/34175173/haskell-could-not-find-module-data-list-split

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!