Advertisement
Guest User

Untitled

a guest
Sep 20th, 2019
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.49 KB | None | 0 0
  1. {-# LANGUAGE GeneralizedNewtypeDeriving #-}
  2. {-# LANGUAGE FlexibleInstances #-}
  3.  
  4. module DataTypePractices where
  5.  
  6. class TooMany a where
  7. tooMany :: a -> Bool
  8.  
  9. instance TooMany Int where
  10. tooMany n = n > 42
  11.  
  12. instance TooMany (Int, Int) where
  13. tooMany (n, m) = n + m > 42
  14.  
  15. newtype Goats =
  16. Goats Int deriving (Eq, Show, TooMany)
  17.  
  18. works1 = tooMany (42 :: Int)
  19. works2 = tooMany (43 :: Int)
  20. works3 = tooMany (Goats 42)
  21. works4 = tooMany (Goats 43)
  22.  
  23. -- does not work
  24. doesNotCompile ((Goats 22), (Goats 22))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement