Last active
August 29, 2015 14:24
-
-
Save hadronized/733d26802f5ae525cb3a to your computer and use it in GitHub Desktop.
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
struct Widget { | |
virtual ~Widget(); | |
virtual void foo() = 0; | |
}; | |
class Label : public Widget { | |
std::string _value; | |
public: | |
Label(std::string const &v) : _value(v) {} | |
~Label() {} | |
override void foo() { | |
std::cout << _value << std::endl; | |
} | |
}; |
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
data Widget = Widget { | |
foo :: IO () | |
} | |
data Label = Label String | |
toWidget :: Label -> Widget | |
toWidget (Label str) = Widget $ putStrLn str |
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
-- encore mieux, pour gérer plus de widgets par la suite | |
data Widget = Widget { | |
foo :: IO () | |
} | |
class ToWidget a where | |
toWidget :: a -> Widget | |
data Label = Label String | |
instance ToWidget Label where | |
toWidget (Label str) = Widget $ putStrLn str |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment