【发布时间】:2011-06-11 07:00:32
【问题描述】:
我正在尝试将 Haskell 程序转换为 Haskell GUI 程序, 但由于我在 Haskell 非常新, 每次我尝试某些东西时,都会遇到很多错误。 我在 Stack Overflow 上多次询问过这个程序, 但只要一个错误消失,就会出现两个错误。
很抱歉问了类似的问题,但是 我打算转换的程序的能力是 非常简单的单词搜索。 接收输入字符串,搜索单词,在窗口打印。
任何建议、提示或示例都会对我很有帮助。
我使用的是 Windows XP。很抱歉代码很糟糕。
--GUI routine
import Graphics.UI.Gtk
import Text.Regex.Posix ((=~))
import Control.Monad (when)
--core routine
matchWord :: String -> String -> Int
matchWord file word = length . filter (== word) . concat $ file =~ "[^- \".,\n]+"
--main start
main :: IO ()
main =
do initGUI
win <- windowNew
windowSetTitle win "WORD SEARCHER"
win `onDestroy` mainQuit
fch <- fileChooserWidgetNew FileChooserActionOpen
containerAdd win fch
targetFile <- fileChooserGetFilename fch --wrong?
ent <- entryNew
btn <- buttonNewWithLabel "Click to search"
st <- labelNew $ Just "Found : 0 "
col <- vBoxNew False 5
containerAdd col ent
containerAdd col btn
containerAdd col st
btn `onClicked` do targetWord <- entryGetText ent
fileData <- readFile Just targetFile
found <- matchWord fileData targetWord
labelSetText st found
containerAdd win col
widgetShowAll win
mainGUI
感谢您的阅读
【问题讨论】:
-
错误是什么?它是如何失败的?
标签: user-interface haskell tui