Advertisement
Guest User

Incoherent Instance example

a guest
Jun 3rd, 2018
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. {-# LANGUAGE FlexibleInstances, UndecidableInstances #-}
  2.  
  3. module UpperLowerBounded where
  4.  
  5. class LowerBounded a where
  6.     lowerBound :: a
  7.  
  8. class UpperBounded a where
  9.     upperBound :: a
  10.  
  11. instance {-# INCOHERENT #-} Bounded a => LowerBounded a where
  12.     lowerBound = minBound
  13.    
  14. instance Bounded a => UpperBounded a where
  15.     upperBound = maxBound
  16.  
  17. instance {-# INCOHERENT #-} (LowerBounded a, UpperBounded a) => Bounded a where
  18.     minBound = lowerBound
  19.     maxBound = upperBound
  20.  
  21. data Foo = A | B deriving (Show)
  22. data Bar = C | D | E deriving (Show)
  23.  
  24. instance Bounded Foo where
  25.     minBound = A
  26.     maxBound = B
  27.  
  28. instance LowerBounded Bar where
  29.     lowerBound = C
  30.  
  31. instance UpperBounded Bar where
  32.     upperBound = E
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement