Created
February 24, 2015 08:00
-
-
Save CMCDragonkai/360b8898a2ac1a989d16 to your computer and use it in GitHub Desktop.
Haskell: Pattern Matching Deconstructor Assignment (Within Functions)
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
tuple1 a b = (a, b) | |
tuple2 a b = (b, a) | |
-- recursive let | |
func1 n = | |
let | |
(a, b) = tuple1 3 n | |
(_, y) = tuple2 a b | |
in | |
a + b + y | |
-- nested let | |
func2 n = | |
let | |
(a, b) = tuple1 3 n | |
in | |
let | |
(_, y) = tuple2 a b | |
in | |
a + b + y | |
-- nested case | |
func3 n = | |
case tuple1 3 n of | |
(a, b) -> case tuple2 a b of | |
(_, y) -> a + b + y | |
-- where | |
func4 n = | |
a + b + y | |
where | |
(a, b) = tuple1 3 n | |
(_, y) = tuple2 a b | |
main = do | |
print.show $ func1 1 | |
print.show $ func2 1 | |
print.show $ func3 1 | |
print.show $ func4 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment