Created
August 16, 2012 07:03
-
-
Save klapaucius/3367586 to your computer and use it in GitHub Desktop.
runtime/compile-time
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Prelude> class Pet a where kill :: a -> String | |
Prelude> data Dog = Dog deriving Show | |
Prelude> data Cat = Cat deriving Show | |
Prelude> instance Pet Dog where kill = const "dead" | |
Prelude> instance Pet Cat where kill = const "c_1|dead> + c_2|alive>" | |
Prelude> map kill [Cat, Cat] -- диспетчеризация времени компиляции | |
["c_1|dead> + c_2|alive>","c_1|dead> + c_2|alive>"] | |
Prelude> map kill [Dog, Dog] -- диспетчеризация времени компиляции | |
["dead","dead"] | |
Prelude> data PetBox where Box :: Pet a => a -> PetBox | |
Prelude> map (\(Box pet) -> kill pet) [Box Dog, Box Cat] -- динамическая диспетчеризация | |
["dead","c_1|dead> + c_2|alive>"] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment