Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- {-# LANGUAGE GeneralizedNewtypeDeriving #-}
- {-# LANGUAGE FlexibleInstances #-}
- module DataTypePractices where
- class TooMany a where
- tooMany :: a -> Bool
- instance TooMany Int where
- tooMany n = n > 42
- instance TooMany (Int, Int) where
- tooMany (n, m) = n + m > 42
- newtype Goats =
- Goats Int deriving (Eq, Show, TooMany)
- works1 = tooMany (42 :: Int)
- works2 = tooMany (43 :: Int)
- works3 = tooMany (Goats 42)
- works4 = tooMany (Goats 43)
- -- does not work
- doesNotCompile ((Goats 22), (Goats 22))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement