Skip to content

Instantly share code, notes, and snippets.

@nskeip
Last active June 21, 2017 19:50
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 nskeip/3784d651ac646a67c5f246f048949af4 to your computer and use it in GitHub Desktop.
Save nskeip/3784d651ac646a67c5f246f048949af4 to your computer and use it in GitHub Desktop.
Moving.hs
{-# LANGUAGE MultiParamTypeClasses, FunctionalDependencies, FlexibleInstances, FlexibleContexts #-}
import Geom2D
left :: (Num a) => Point a -> a -> Point a
left (Point x y) n = Point (x - n) y
right :: (Num a) => Point a -> a -> Point a
right (Point x y) n = Point (x + n) y
up :: (Num a) => Point a -> a -> Point a
up (Point x y) n = Point x (y - n)
down :: (Num a) => Point a -> a -> Point a
down (Point x y) n = Point x (y + n)
class Num n => Moving p n | p -> n where
up' :: n -> p -> p
down' :: n -> p -> p
up' n = down' (-n)
down' n = up' (-n)
instance Num a => Moving (Point a) a where
up' n (Point x y) = Point x (y - n)
p = Point 0 0
main = print $ up' 10 p
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment