简体   繁体   中英

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 (). I then want to generate a list of type String that holds all the matches by a pattern from that web page.

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.

EDIT


The actual scraper which I got from here works simply like this:

在此处输入图片说明

Imagine 'src' is my 'html' variable

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:

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

into this:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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