-
-
Save buggymcbugfix/0cab91093559c45848c07bfa52063af9 to your computer and use it in GitHub Desktop.
Sums numbers on the command line.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/env stack | |
-- stack --resolver lts-8.15 --install-ghc script --package base | |
{-# LANGUAGE ScopedTypeVariables #-} | |
-- Usage: | |
-- $ echo -e "1.2 3.4\n5.6 not-a-number" | ./total.hs | |
-- 10.2 | |
import Data.Maybe (mapMaybe) | |
import Text.Read (readMaybe) | |
main = print . sum . mapMaybe (readMaybe :: String -> Maybe Double) . words =<< getContents |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment