Search code examples
haskellhunspell

Haskell binding for hunspell


Is there a Haskell binding for the Hunspell spell checking library?

If not, is it possible to send the words to check to the Hunspell CLI program and retrieve the results?


Solution

  • This is an answer to your second question:

    If not, is it possible to send the words to check to the Hunspell CLI program and retrieve the results?

    You can use the shelly library to call any cli program in your PATH. Assume foo is your program and param1, param2 and param3 are the needed parameters: foo param1 param2 param3 would be the call in a OS shell.

    Here is a small Haskell example:

    {-# LANGUAGE OverloadedStrings #-}
    import Shelly
    import qualified Data.Text as T
    
    main :: IO ()
    main = shelly $ silently $ do
        out <- run "foo" ["param1", "param2", "param3"] 
        -- lns will containes a list of lines with the stdout output of foo
        let lns = T.lines out
        -- Here we print out the number of lines and the first 5 lines
        liftIO $ putStrLn $ show $ Prelude.length lns
        liftIO $ mapM_ (putStrLn .T.unpack) $ take 5 lns