Advertisement
Guest User

Untitled

a guest
Sep 22nd, 2014
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.25 KB | None | 0 0
  1. data Person = Person String
  2. data Pet = Pet String
  3. data Owns = Owns
  4. data Desires = Desires
  5. instance Relation Owns Person Pet
  6. instance Relation Desires Person Pet
  7.  
  8. data PetAttachment = AttachOwns | AttachDesires
  9.  
  10. personPets :: Person -> PetAttachment -> Graph -> [Pet]
  11. personPets person att g =
  12. neighbours person r g
  13. where
  14. r = case PetAttachment of
  15. AttachOwns -> Owns
  16. AttachDesires -> Desires
  17.  
  18. r :: forall r. Relation r Person Pet => r
  19.  
  20. {-# LANGUAGE ExistentialQuantification #-}
  21. {-# LANGUAGE MultiParamTypeClasses #-}
  22. {-# LANGUAGE FlexibleContexts #-}
  23.  
  24. data Graph = Graph
  25.  
  26. class Relation r a b where
  27. relation :: (r,a,b) -> Int
  28.  
  29. neighbours :: forall r a b. Relation r a b => a -> r -> Graph -> [b]
  30. neighbours = undefined
  31.  
  32. data Person = Person String
  33. data Pet = Pet String
  34. data Owns = Owns
  35. data Desires = Desires
  36. instance Relation Owns Person Pet where
  37. relation _ = 1
  38. instance Relation Desires Person Pet where
  39. relation _ = 2
  40.  
  41. data PetAttachment = AttachOwns | AttachDesires
  42.  
  43. personPets :: Person -> PetAttachment -> Graph -> [Pet]
  44. personPets person att =
  45. neighbours person r
  46. where
  47. r :: forall r. Relation r Person Pet => r
  48. r = case att of
  49. AttachOwns -> Owns
  50. AttachDesires -> Desires
  51.  
  52. main :: IO ()
  53. main = undefined
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement