Skip to content

Instantly share code, notes, and snippets.

@ghais
Last active February 22, 2021 01:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ghais/2911a582d712a4cafe244b826654cdab to your computer and use it in GitHub Desktop.
Save ghais/2911a582d712a4cafe244b826654cdab to your computer and use it in GitHub Desktop.
{-# 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