Created
June 14, 2013 03:35
-
-
Save CindyLinz/5779282 to your computer and use it in GitHub Desktop.
sample usage for lazy pattern matching
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
module Main where | |
fetch :: [Int] -> Int | |
fetch args = | |
let | |
(n : ~(a : ~(b : ~(c : x)))) = args | |
in | |
if n == 1 | |
then a | |
else if n == 2 | |
then a + b | |
else a + b + c | |
main = do | |
putStrLn $ show (fetch [1, 5]) | |
putStrLn $ show (fetch [2, 5, 10]) | |
putStrLn $ show (fetch [3, 5, 10, 15]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment