Last active
February 22, 2021 01:15
-
-
Save ghais/2911a582d712a4cafe244b826654cdab to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# LANGUAGE ScopedTypeVariables #-} | |
type Speed = Double | |
type Name = String | |
class Ship s c where | |
sail :: s -> c -> Speed | |
data Sea s c = Sea { | |
ships :: M.Map (Name) s | |
} | |
data Cartesian = Cartesian | |
class Coordinate c where | |
toCartesian :: c -> Cartesian | |
fromCartesian :: Cartesian -> c | |
sailShip :: forall s c. (Coordinate c, Ship s c) => Sea s c -> Name -> Cartesian -> Speed | |
sailShip sea name c = let | |
cord1 = fromCartesian c::c | |
cord2 = toCartesian cord1 | |
cord3 = fromCartesian cord2::c | |
ship = ships sea M.! name | |
in sail ship cord3 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment