fork(4) download
  1. {-# LANGUAGE FlexibleInstances #-}
  2.  
  3. unOp :: Read a => Show b => (a -> b) -> String -> String
  4. unOp f x = show . f $ read x
  5.  
  6. binOp :: Read a => Read b => Show c => (a -> b -> c) -> String -> String -> String
  7. binOp f x y = show $ read x `f` read y
  8.  
  9. instance Num String where
  10. (+) = binOp (+)
  11. (*) = binOp (*)
  12. abs = unOp abs
  13. signum = unOp signum
  14. negate = unOp negate
  15.  
  16. main = print $ 2 + 2 == "4"
Success #stdin #stdout 0s 8388607KB
stdin
Standard input is empty
stdout
True