简体   繁体   English

Haskell Regex - 无法将类型“[Char]”与“IO()”错误匹配

[英]Haskell Regex - Couldn't match type ‘[Char]’ with ‘IO () error

Within Haskell I have a program that scrapes the html off a page and stores it in a variable called 'html' which is type IO ().在 Haskell 中,我有一个程序可以从页面上刮下html 并将其存储在一个名为 'html' 的变量中,该变量是类型 IO ()。 I then want to generate a list of type String that holds all the matches by a pattern from that web page.然后我想生成一个 String 类型的列表,该列表通过来自该网页的模式保存所有匹配项。

These two lines below generate a list of matches from the pattern下面这两行从模式生成匹配列表

let pattern = "..." --note, regex is omited
html =~ pattern :: String -> IO String

I get the error:我收到错误:

在此处输入图片说明

What I want to do is something like:我想做的是:

 let pattern = "..." 
 let matches_list = html =~ pattern :: String -> IO String 

Where matches_list of type String is a list of matches.其中字符串类型的matches_list 是匹配列表。

EDIT编辑


The actual scraper which I got from here works simply like this:我从这里得到的实际刮板的工作原理如下:

在此处输入图片说明

Imagine 'src' is my 'html' variable想象一下 'src' 是我的 'html' 变量

You are trying to cast the result of the regular expression matcher into a function that takes a string and returns an IO String , but based on your description, it sounds like you'd rather just cast it into a list of strings, and although you haven't specified what regular expression library you are using, your fix is probably as simple as changing this:您正在尝试将正则表达式匹配器的结果转换为一个接受字符串并返回IO String的函数,但根据您的描述,听起来您宁愿将其转换为字符串列表,尽管您尚未指定您正在使用的正则表达式库,您的修复可能就像更改此内容一样简单:

let matches_list = html =~ pattern :: String -> IO String 

into this:进入这个:

let matches_list = html =~ pattern :: [String]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM