Please help me writing a function which takes two arguments: a list of ints and an index (int) and returns a list of integers with negative values on specified index position in the table.
The function would have this signatureMyReverse :: [Int]->Int->[Int].
For example: myReverse [1,2,3,4,5] 3 = [1,2,-3,4,5].
If the index is bigger than the length of the list or smaller than 0, return the same list.
That’s indexing the array from
0; your example indexes from1, but is undefined for the casen == 0. The fix to take it to index from1should be fairly obvious 🙂Also, your capitalisation is inconsistent;
MyReverseis different tomyReverse, and only the latter is valid as a function.Results, in GHCi:
More generic version that does the same thing, using a pointless definition for
myReverse: