3 ms·
Being such a concise language, Haskell could be a good option here. You can do quick scripting while still having a powerful type system (especially compared to
by watshn 8y ago
Being such a concise language, Haskell could be a good option here. You can do quick scripting while still having a powerful type system (especially compared to Go's) backing you up. I somewhat quickly typed this code up and haven't tested it, but it should replicate that bash script pretty closely:
#!/usr/bin/env stack
-- stack script --resolver=lts-12.2
import System.Process (system)
import Control.Lens
import Crypto.Hash.SHA256
import qualified Data.Bytestring.Lazy as B
import Network.Wreq
url = "https://example.com"
mem = "memory.txt"
main = do
oldsum <- B.readFile mem
newsum <- (hashLazy . view responseBody) <$> get url
when (oldsum /== newsum) $ do
exitCode <- system $ "xmpp_notify " ++ url ++ " changed"
B.writeFile mem newsum
I didn't make use of it, but there's also the Turtle library which aims to provide a fairly solid shell scripting experience, providing a lot of coreutils as simple Haskell functions. You also get a REPL in the form of GHCI, which comes default in Haskell installations.