Haskell プログラムを Haskell GUI プログラムに変換しようとしていますが、Haskell に慣れていないため、何かを試みるたびに多くのエラーが発生します。このプログラムをスタックオーバーフローで何度も聞いたのですが、エラーが消えるたびに2つのエラーが発生します。
同様の質問をして申し訳ありませんが、変換しようとしているプログラムの機能は非常に単純な単語検索です。入力文字列を受け取り、単語を検索し、ウィンドウに出力します。
アドバイス、ヒント、または例は、私にとって非常に役立ちます。
私は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
読んでくれてありがとう