Created
June 15, 2016 00:24
-
-
Save dmp1ce/489a8f3619feb8763120c01cf5d7f436 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
-- | A library to do stuff. | |
module Lib | |
( | |
ourAdd | |
, fun1 | |
, fun1' | |
, fun2 | |
, fun2' | |
) where | |
-- Allow a modifier to QuickCheck for very small integers | |
import Test.QuickCheck.Arbitrary | |
import Test.QuickCheck.Gen | |
instance Arbitrary Integer where | |
arbitrary = choose (0, 1000) | |
-- | Add two 'Int' values. | |
ourAdd :: Int -- ^ left | |
-> Int -- ^ right | |
-> Int -- ^ sum | |
ourAdd x y = x + y | |
fun1 :: [Integer] -> Integer | |
fun1 [] = 1 | |
fun1 (x:xs) | |
| even x = (x - 2) * fun1 xs | |
| otherwise = fun1 xs | |
fun1' :: [Integer] -> Integer | |
fun1' = foldl (\acc x -> acc*(x - 2)) 0 . takeWhile even | |
fun2 :: Integer -> Integer | |
fun2 1 = 0 | |
fun2 n | even n = n + fun2 (n `div` 2) | |
| otherwise = fun2 (3 * n + 1) | |
fun2' :: Integer -> Integer | |
fun2' x = 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment