Guest User

Untitled

a guest
Aug 6th, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import Control.Category ((>>>))
  2. import Data.List (intercalate)
  3.  
  4. data Product = Product { name   :: String
  5.                        , vendor :: String
  6.                        , price  :: Float
  7.                        } deriving (Read)
  8.  
  9. instance Show Product where
  10.     show (Product name' vendor' price') = vendor' ++ " " ++ name' ++ " — " ++ (show price')
  11.  
  12. isValid p = all ($ p) predicates
  13.     where
  14.         nameValid   = name   >>> not . null
  15.         vendorValid = vendor >>> not . null
  16.         priceValid  = price  >>> (> 0)
  17.         predicates  = [nameValid, vendorValid, priceValid]
  18.  
  19. parseProducts :: String -> [Product]
  20. parseProducts = map read . lines
  21.  
  22. main :: IO ()
  23. main = getContents >>= mapM_ print . filter isValid . parseProducts
Add Comment
Please, Sign In to add comment