Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- https://github.com/Dobiasd/articles/blob/master/from_oop_to_fp_-_inheritance_and_the_expression_problem.md
- module Base where
- import Data.List
- data Base = Foo Int | Bar String
- step (Foo intVal) delta = Foo $ intVal + delta
- step (Bar strVal) delta = Bar $ strVal ++ show delta
- display (Foo intVal) = show intVal
- display (Bar strVal) = strVal
- stepAll l = map (\b -> step b 1) l
- displayAll l = putStrLn $ concat (intersperse "\n" $ map display l)
- main =
- displayAll ((stepAll . stepAll . stepAll) [Foo 0, Bar ""])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement