Created
May 10, 2010 15:30
-
-
Save jutememo/396181 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
data Hoge a = Hoge a | |
data Piyo a = Piyo { left, right :: a } | |
class Container c where | |
get :: c a -> a | |
getf :: (a -> b) -> c a -> b | |
instance Container Hoge where | |
get (Hoge x) = x | |
getf f (Hoge x) = f x | |
instance Container Piyo where | |
get (Piyo l r) = l | |
getf f (Piyo l r) = f l | |
main = do let h = Hoge 100 | |
p = Piyo "p1" "p2" | |
print $ get h -- 100 | |
print $ get p -- "p1" | |
print $ getf (*2) h -- 200 | |
print $ getf (replicate 2) p -- ["piyo", "piyo"] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment