Skip to content

Instantly share code, notes, and snippets.

@CindyLinz
Created June 14, 2013 03:35
Show Gist options
  • Save CindyLinz/5779282 to your computer and use it in GitHub Desktop.
Save CindyLinz/5779282 to your computer and use it in GitHub Desktop.
sample usage for lazy pattern matching
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