Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
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