Created
November 20, 2016 02:33
-
-
Save bolerap/70c93748bd09994625e59ab264485eff 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
-- define max function accept two number and return greater number | |
max :: Ord a => a -> a -> a | |
-- single line function equation | |
max x y = if x >= y then x else y | |
-- multiple line function equation (Guard style -> this is idiomatic haskell) | |
max x y | x >= y = x | |
| otherwise = y | |
-- signum function (Ord a, Num a) meant type variable a can belong both type class Ord and Num | |
signum :: (Ord a, Num a) => a -> Int | |
-- single line function equation | |
signum x = if x < 0 then -1 else if x == 0 then 0 else 1 | |
-- multiple line function equation (Guard) | |
signum x | x < 0 = -1 | |
| x == 0 = 0 | |
| otherwise = 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment