Skip to content

Instantly share code, notes, and snippets.

@vst
Created June 15, 2020 02:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vst/f4a82377f1b3a3aa2113b740802993c2 to your computer and use it in GitHub Desktop.
Save vst/f4a82377f1b3a3aa2113b740802993c2 to your computer and use it in GitHub Desktop.
Demonstrate how to use Stack for scripts (+email address validation)
{- stack script
--resolver lts-16.0
--package bytestring
--package email-validate
--ghc-options -Wall
--install-ghc
--compile
-}
-- * Command Line Usage:
--
-- >>> echo "invalid\nvalid@email-address.com" | stack ParseEmail.hs
-- - invalid (at sign > @: not enough input)
-- + valid@email-address.com
{-# LANGUAGE OverloadedStrings #-}
import qualified Data.ByteString.Char8 as BC
import System.IO (stderr)
import Text.Email.Validate (validate)
main :: IO ()
main = mapM_ validateAndShow =<< BC.lines <$> BC.getContents
validateAndShow :: BC.ByteString -> IO ()
validateAndShow s =
case validate s of
Left e -> BC.hPutStrLn stderr ("- " <> s <> " (" <> BC.pack e <> ")")
Right _ -> BC.putStrLn ("+ " <> s)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment