Skip to content

Instantly share code, notes, and snippets.

@dmp1ce
Created June 15, 2016 00:24
Show Gist options
  • Save dmp1ce/489a8f3619feb8763120c01cf5d7f436 to your computer and use it in GitHub Desktop.
Save dmp1ce/489a8f3619feb8763120c01cf5d7f436 to your computer and use it in GitHub Desktop.
-- | 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