Find Jobs
Hire Freelancers

Writing Simple Haskell Functions

£10-20 GBP

Closed
Posted over 4 years ago

£10-20 GBP

Paid on delivery
[login to view URL] a function count_odds that produces the number of odds in a list of numbers. For example, count_odds [1,2,3,4,7,8] should return 3. 2. Write a function remove_last_two that removes the last two elements in a list. If the list contains two or less elements, then it should return the list unchanged. For example, remove_last [1,2,3,4,5,6] should return [1,2,3,4]. 3. Using library functions, define a function halve :: [a ] → ([a ], [a ]) that splits an even-length list into two halves. For example, halve [1, 2, 3, 4, 5, 6] should return ([1, 2, 3], [4, 5, 6]). 4. Write a function min_max that takes a list of numbers and returns the minimum, as well as the maximum element in the list as a pair. For example, min_max [4,3,6,5,9,10,8] should return (3,10) as the answer. 5. Redefine the function mult x y z = x * y * z using lambda expressions. 6. Write a function primes_before that takes a natural number n and returns in a list the prime numbers that are smaller than n. For example, primes_before 10 should return [2,3,5,7]. 7. Write a function sum_average_count that takes a list of numbers and returns as a triple the sum, average and count of the numbers. For example, sum_average_count [2,4,12] should return (18,6,3). 8. Write a function to_list that takes a tuple of three components and returns the list of those components. For example, to_list (3,4,5) should return [3,4,5].
Project ID: 21811327

About the project

3 proposals
Remote project
Active 4 yrs ago

Looking to make some money?

Benefits of bidding on Freelancer

Set your budget and timeframe
Get paid for your work
Outline your proposal
It's free to sign up and bid on jobs
3 freelancers are bidding on average £15 GBP for this job
User Avatar
This is pretty easy. I've already done most of it. Here is all but the prime number problem which I can do in 5 minutes: count_odds :: Integral a => [a] -> a count_odds = foldr addOneIfOdd 0 where addOneIfOdd a b = if odd a then b + 1 else b remove_last_two :: Num a => [a] -> [a] remove_last_two [] = [] remove_last_two [x] = [x] remove_last_two [x,y] = [x,y] remove_last_two (_:xs) = remove_last_two xs halve :: Num a => [a] -> ([a],[a]) halve l = splitAt (length l `div` 2) l min_max :: (Num a, Ord a) => [a] -> (a,a) min_max [] = error "min_max expected a non-empty list" min_max [x] = (x,x) min_max (x:xs) = foldr pickMinMax (x,x) xs where pickMinMax a (minX, maxX) = (min minX a, max maxX a) mult :: Num a => a -> a -> a -> a mult = \z -> \y -> \x -> (x * y * z) primes_before :: Num a => [a] -> [a] primes_before = error "to be written" sum_average_count :: (Fractional b, Integral a, Integral c) => [a] -> (a, b, c) sum_average_count [] = error "sum_average_count expected a non-empty list" sum_average_count [x] = (x,fromIntegral x,1) sum_average_count (x:xs) = (sumX, fromIntegral sumX / fromIntegral countX, countX) where (sumX,countX) = foldr sumAndCount (x,1) xs sumAndCount a (sumX,countX) = (sumX + a, countX + 1) to_list :: (a,a,a) -> [a] to_list (a,b,c) = [a,b,c]
£15 GBP in 1 day
5.0 (11 reviews)
3.3
3.3
User Avatar
Hi I have already developed the functions requested , greetings.
£10 GBP in 1 day
0.0 (0 reviews)
0.0
0.0
User Avatar
Hello. I am a Haskell programmer from academia. I developed various Haskell programs including monadic ones in several projects. I understand that the project is about simple list processing. I ensure that I can complete all the functions within one day.
£20 GBP in 1 day
0.0 (0 reviews)
0.0
0.0

About the client

Flag of UNITED KINGDOM
Canterbury, United Kingdom
0.0
0
Payment method verified
Member since Oct 16, 2019

Client Verification

Thanks! We’ve emailed you a link to claim your free credit.
Something went wrong while sending your email. Please try again.
Registered Users Total Jobs Posted
Freelancer ® is a registered Trademark of Freelancer Technology Pty Limited (ACN 142 189 759)
Copyright © 2024 Freelancer Technology Pty Limited (ACN 142 189 759)
Loading preview
Permission granted for Geolocation.
Your login session has expired and you have been logged out. Please log in again.