Created
July 20, 2019 11:48
-
-
Save mrcrilly/dbb7b3f92a1f70f36f6fcfdb6e9d881c to your computer and use it in GitHub Desktop.
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
module Simple where | |
inc, increment :: Num a => a -> a | |
inc x = x + 1 | |
increment x = inc x | |
double :: Int -> Int | |
double x = x * 2 | |
exclaim :: String -> String | |
exclaim x = x ++ "!!" | |
average :: Fractional a => a -> a -> a | |
average a b = (a + b) / 2 | |
-- square :: Int -> Int | |
square' x = x * x | |
showResult :: Int -> String | |
showResult x = "The result is " ++ (show x) | |
areaOfCircle :: Float -> String | |
areaOfCircle f = | |
"r = " ++ (show f) ++ " == " ++ (show (pi * (f^2))) ++ "cm^2" | |
circleArea' :: Floating a => a -> a | |
circleArea' x = pi * radius * radius | |
where | |
radius = x / 2.0 | |
addMul :: Num a => a -> a -> (a,a) | |
addMul x y = (x+y, x*y) | |
maxNum :: Ord a => a -> a -> a | |
maxNum x y = if x >= y then x else y | |
-- --- | |
type Point = (Int, Int) | |
-- origin :: Point | |
-- origin = (0, 0) | |
moveRight :: Point -> Int -> Point | |
moveRight (x,y) z = (x+z, y) | |
moveUp :: Point -> Int -> Point | |
moveUp (x,y) z = (x, y+z) | |
type Colour = String | |
type ColourPoint = (Int, Int, Colour) | |
c1 = (10, 10, "red") | |
c2 = (90, 90, "yellow") | |
colourOfPoint :: ColourPoint -> String | |
colourOfPoint (x, y, c) = c | |
origin :: Colour -> ColourPoint | |
origin colour = (0, 0, colour) | |
moveColourPoint :: ColourPoint -> Int -> Int -> ColourPoint | |
moveColourPoint (x,y,c) dx dy = (x+dx,y+dy,c) | |
distanceBetween :: ColourPoint -> ColourPoint -> Float | |
distanceBetween (x1,y1,c1) (x2,y2,c2) | |
= sqrt(fromIntegral (dx * dx + dy * dy)) | |
where | |
dx = x2 - x1 | |
dy = y2 - y1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment