Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- {-# LANGUAGE ExistentialQuantification #-}
- module Network.Currycraft.Entity where
- class EntityC a where
- posX :: a -> Double
- posY :: a -> Double
- posZ :: a -> Double
- data Entity = forall e. (Show e, EntityC e) => Entity e
- instance Show Entity where
- show (Entity e) = show e
- {- Contains X,Y,Z only-}
- data SimpleEntity = SimpleEntity Double Double Double deriving (Show)
- instance EntityC SimpleEntity where
- posX (SimpleEntity x _ _) = x
- posY (SimpleEntity _ y _) = y
- posZ (SimpleEntity _ _ z) = z
- {- Containsz X,Y,Z and a first and last name-}
- data ComplexEntity = ComplexEntity Double Double Double String String deriving (Show)
- instance EntityC ComplexEntity where
- posX (ComplexEntity x _ _ _ _) = x
- posY (ComplexEntity _ y _ _ _) = y
- posZ (ComplexEntity _ _ z _ _) = z
- firstName :: ComplexEntity -> String
- firstName (ComplexEntity _ _ _ fn _) = fn
- lastName :: ComplexEntity -> String
- lastName (ComplexEntity _ _ _ ln _) = ln
- listEntities :: [Entity] -> [String]
- listEntities = map show
Add Comment
Please, Sign In to add comment