Skip to content

Instantly share code, notes, and snippets.

@jutememo
Created May 10, 2010 15:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jutememo/396181 to your computer and use it in GitHub Desktop.
Save jutememo/396181 to your computer and use it in GitHub Desktop.
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