Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- data Person = Person String
- data Pet = Pet String
- data Owns = Owns
- data Desires = Desires
- instance Relation Owns Person Pet
- instance Relation Desires Person Pet
- data PetAttachment = AttachOwns | AttachDesires
- personPets :: Person -> PetAttachment -> Graph -> [Pet]
- personPets person att g =
- neighbours person r g
- where
- r = case PetAttachment of
- AttachOwns -> Owns
- AttachDesires -> Desires
- r :: forall r. Relation r Person Pet => r
- {-# LANGUAGE ExistentialQuantification #-}
- {-# LANGUAGE MultiParamTypeClasses #-}
- {-# LANGUAGE FlexibleContexts #-}
- data Graph = Graph
- class Relation r a b where
- relation :: (r,a,b) -> Int
- neighbours :: forall r a b. Relation r a b => a -> r -> Graph -> [b]
- neighbours = undefined
- data Person = Person String
- data Pet = Pet String
- data Owns = Owns
- data Desires = Desires
- instance Relation Owns Person Pet where
- relation _ = 1
- instance Relation Desires Person Pet where
- relation _ = 2
- data PetAttachment = AttachOwns | AttachDesires
- personPets :: Person -> PetAttachment -> Graph -> [Pet]
- personPets person att =
- neighbours person r
- where
- r :: forall r. Relation r Person Pet => r
- r = case att of
- AttachOwns -> Owns
- AttachDesires -> Desires
- main :: IO ()
- main = undefined
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement