Advertisement
Guest User

Untitled

a guest
Jan 21st, 2017
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. -- A type class with a single instance
  2. class C a where
  3.     c :: a -> a
  4. instance D a => C a where
  5.     c = d
  6.  
  7. -- Asking for the type of c will give me a function with the constraint D a:
  8. $ :t c
  9. > D a => a -> a
  10.  
  11. -- However, I want the type to be C a => a -> a
  12. -- One way to solve this is by adding another instance that should never match
  13.  
  14. data Bottom
  15. instance C Bottom where
  16.    c = undefined
  17.  
  18. -- Now the type will have the correct constraint
  19. $ :t c
  20. > C a => a -> a
  21.  
  22. -- Is there another way of solving this?
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement