Guest User

Untitled

a guest
Jul 16th, 2018
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.01 KB | None | 0 0
  1. {-# LANGUAGE ExistentialQuantification #-}
  2.  
  3. module Network.Currycraft.Entity where
  4.  
  5. class EntityC a where
  6. posX :: a -> Double
  7. posY :: a -> Double
  8. posZ :: a -> Double
  9.  
  10. data Entity = forall e. (Show e, EntityC e) => Entity e
  11.  
  12. instance Show Entity where
  13. show (Entity e) = show e
  14.  
  15. {- Contains X,Y,Z only-}
  16. data SimpleEntity = SimpleEntity Double Double Double deriving (Show)
  17.  
  18. instance EntityC SimpleEntity where
  19. posX (SimpleEntity x _ _) = x
  20. posY (SimpleEntity _ y _) = y
  21. posZ (SimpleEntity _ _ z) = z
  22.  
  23. {- Containsz X,Y,Z and a first and last name-}
  24. data ComplexEntity = ComplexEntity Double Double Double String String deriving (Show)
  25.  
  26. instance EntityC ComplexEntity where
  27. posX (ComplexEntity x _ _ _ _) = x
  28. posY (ComplexEntity _ y _ _ _) = y
  29. posZ (ComplexEntity _ _ z _ _) = z
  30.  
  31. firstName :: ComplexEntity -> String
  32. firstName (ComplexEntity _ _ _ fn _) = fn
  33.  
  34. lastName :: ComplexEntity -> String
  35. lastName (ComplexEntity _ _ _ ln _) = ln
  36.  
  37. listEntities :: [Entity] -> [String]
  38. listEntities = map show
Add Comment
Please, Sign In to add comment