[ create a new paste ] login | about

Link: http://codepad.org/XRnantkj    [ raw code | output | fork ]

Haskell, pasted on Mar 10:
-- $setup
-- >>> import Test.QuickCheck
-- >>> import Control.Applicative

-- | maybeReadPositiveInt Try to parse a positive Int
-- Can be done point-free (and it's probably funnier this way).
--
-- Examples:
--
-- prop> (==) <$> Just <*> maybeReadPositiveInt . show $ getNonNegative x
--
-- prop> Nothing == (maybeReadPositiveInt . show . negate . getPositive $ x)
--
-- >>> maybeReadPositiveInt "foo"
-- Nothing
--
-- >>> maybeReadPositiveInt "12 "
-- Nothing


maybeReadPositiveInt :: String -> Maybe Int
maybeReadPositiveInt = undefined

main = do
  print $ maybeReadPositiveInt "12" -- Just 12
  print $ maybeReadPositiveInt "-12" -- Nothing
  print $ maybeReadPositiveInt "12 a" -- Nothing
  print $ maybeReadPositiveInt "12 " -- Nothing


Output:
1
Timeout


Create a new paste based on this one


Comments: