Question: Note: This question has been asked before by me, but the answers had errors and I can't reply to the original post. I am also

Note: This question has been asked before by me, but the answers had errors and I can't reply to the original post. I am also not allowed to post links. I recommend looking at my original posts for context and background information of this question.

Thanks for the help so far guys, but my Haskell code still gets some errors.

Here's the original question post:

Please write the program in Haskell. This is the content of the sort1.txt file:

[(1,2),(3,4),(1,3),(2,4),(2,3)]

Note: This question has been asked before by me, but the answers

had errors and I can't reply to the original post. I am

also not allowed to post links. I recommend looking at my original

This is my code so far:

-- START CODE:

import Data.List (sortBy)

type Comparator = (Int, Int)

-- Applies a single comparator to the input sequence applyComparator :: Comparator -> [Int] -> [Int] applyComparator (i, j) xs | xs !! i

-- Applies a list of comparators to the input sequence applyComparators :: [Comparator] -> [Int] -> [Int] applyComparators comparators xs = foldl (flip applyComparator) xs comparators

-- Reads a list of comparators from a file readComparators :: FilePath -> IO [Comparator] readComparators filename = do contents

-- Runs the comparator network on an input sequence and prints the result runNetwork :: FilePath -> [Int] -> IO () runNetwork filename xs = do comparators

-- Parses the command-line arguments and runs the network

main :: IO () main = do args

--END CODE

I get this error initially:

posts for context and background information of this question. Thanks for the

I tried fixing this by indenting:

help so far guys, but my Haskell code still gets some errors.

But now, I get a different error:

Here's the original question post: Please write the program in Haskell. This

I've tried different ways to indent, but none of them worked.

Thanks!

For this part, you have to implement running a comparator network on an input sequence. The command-line for this is Run filename sequence where filename is the name for a file containing a comparator network (like sort1.txt), and sequence is a list like [5,1,3,0]. You may assume that the list is in the correct format, that all numbers in the list are distinct, and that its length is equal to the biggest wire number in the comparator network that will be used. You should print out the result of applying the network to the sequence. Just print it to the standard-output channel of the program using a function like putStrLn, and print it out in the Haskell format for lists of integers (you can just call show on a list you compute in your code). There is a public test to check that the running sort1.txt on [5,1,3,0] produces [0,1,3,5]. main.hs:93:11: error: Variable not in scope: getArgs : IO [String] 93 args - getArgs main.hs:96:17: error: parseerroroninputrunketwork96runketworkfilenamesequencemamaman

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!