Last active
June 21, 2017 19:50
-
-
Save nskeip/3784d651ac646a67c5f246f048949af4 to your computer and use it in GitHub Desktop.
Moving.hs
This file contains hidden or 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 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