Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6006635
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T01:34:05+00:00 2026-05-23T01:34:05+00:00

I am trying to convert a Haskell program to a Haskell GUI program, but

  • 0

I am trying to convert a Haskell program to a Haskell GUI program,
but since I am very very new at Haskell,
every time I try something I get lots of errors.
I asked on Stack Overflow many time for this program,
but whenever an error disappears, two errors arise.

Sorry for asking similar question, but
the program’s ability what I intend to convert is
very simple word searching.
Receive input string, search the word, print on window.

Any advice, hint or example would be very helpful for me.

I am on Windows XP. Sorry for very poor code.

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

thank you for reading

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T01:34:06+00:00Added an answer on May 23, 2026 at 1:34 am

    This will get you started.

    targetFile <- fileChooserGetFilename fch
    

    At this point, targetFile has type Maybe String; that is, it will return either Just "somestring" or Nothing. You want the "somestring" part, if it’s available. You can get it by pattern matching:

    Just targetFile <- fileChooserGetFilename fch
    

    This will fail with an opaque error message if the result of fileChooserGetFilename returned Nothing. For more robustness you can case analyse the result:

    maybeTargetFile <- fileChooserGetFilename fch
    targetFile <- case maybeTargetFile of
                      Nothing -> fail "I need a filename!"
                      Just file -> return file
    

    The other problem is in this line:

    found <- matchWord fileData targetWord
    

    x <- m is used to bind the result of an action m into the variable x, but matchWord returns an Int, not an action (eg. IO a for some a).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to convert some code that worked great in VB, but I can't
I'm trying convert some decimals to varchar , but they are getting rounded .
Trying to convert the following but am having difficulty. Can anyone see where I'm
I am trying to convert a date/time string in this format YYYY/MM/DD/HH:MM:SS to a
I'm trying to convert this C printf to C# printf(%c%c,(x>>8)&0xff,x&0xff); I've tried something like
I am trying to convert a macro in C to something that would work
I am trying to convert a standard std::string into an NSString but I'm not
I'm trying to convert this function into PHP but somehow it does not give
i trying to convert time in string format to minutes. i can use substring
I am trying to convert scheme code to Haskell code. For that, I want

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.