Advertisement
jckuri

Base1.hs

May 1st, 2014
268
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. -- https://github.com/Dobiasd/articles/blob/master/from_oop_to_fp_-_inheritance_and_the_expression_problem.md
  2.  
  3. module Base where
  4.  
  5. import Data.List
  6.  
  7. data Base = Foo Int | Bar String
  8.  
  9. step (Foo intVal) delta = Foo $ intVal + delta
  10. step (Bar strVal) delta = Bar $ strVal ++ show delta
  11.  
  12. display (Foo intVal) = show intVal
  13. display (Bar strVal) = strVal
  14.  
  15. stepAll l = map (\b -> step b 1) l
  16.  
  17. displayAll l = putStrLn $ concat (intersperse "\n" $ map display l)
  18.  
  19. main =
  20.  displayAll ((stepAll . stepAll . stepAll) [Foo 0, Bar ""])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement