Created
October 24, 2011 16:15
-
-
Save rauhryan/1309414 to your computer and use it in GitHub Desktop.
This file contains 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
add :: Integer -> Integer -> Integer | |
add (a, b) = a + b; | |
-- Haskell allows me to call the function two ways | |
-- prefix notation | |
add (1,2) -- 3 | |
-- infix notation | |
1 `add` 2 -- 3 |
This file contains 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
function a_plus_abs_b(a, b) { | |
return (b > 0 ? plus : subtract)(a, b); | |
// can't return +; #sadpanda | |
function plus(a, b) { return a + b; }; | |
// can't return -; #sadpanda | |
function subtract(a, b) { return a - b; }; | |
} |
This file contains 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 (a-plus-abs-b a b) | |
((if (> b 0) + -) a b)) |
This file contains 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 (a-plus-abs-b a b) | |
((if (> b 0) + -) a b)) | |
(a-plus-abs-b 4 -5) ; returns 9 | |
(+ 4 -5) ; returns -1 | |
(- 4 -5) ; returns 9 | |
(= | |
(a-plus-abs-b 4 -5) | |
(+ 4 -5)) ; False | |
(= | |
(a-plus-abs-b 4 -5) | |
(- 4 -5)) ; True |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment