Better HN
topnewbestaskshowjobs
Log inSign up

watshn

3 karma · joined Aug 5, 2018 (8y ago) · 2 submissions

Submissions

comment 8y ago · link · parent

While true, that issue arose because you restricted their types. Without the type annotations it would have worked just fine, because the (+) function is polymorphic in the Num typeclass, and because literals are overloaded such that the literal 1 will have type Fractional a when type inference calls for it.

So in ghci:

  Prelude> let x = 1 + 1.0
  Prelude> :t x
  x :: Fractional a => a
  Prelude> x
  2.0

comment 8y ago · link · parent

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.