Monday, 15 July 2013

haskell - How should I use maximumBy and compare to implement my function? -


I have to do a LZW compression in Haskell and I'm having some difficulty with the old prefix search because I use it Is a combination of maximum to and comparison functions

The function signature should be the following:

  longest :: [(int, string)] - & gt; (Int, string)  

Here are some tests that describe the requirements:

  test_longest = [longest ([30, "A") , (20, "ABC"), == (20, "ABC"), longest ([30, "A"], (20, "ABC"), (15) , "ABC")] == (15, "ABC")]  

Any help would be appreciated

the longest (x: xs ) = Maximum (compare (length) x) xs code>

But something is definitely off.

This is what it will:

  import data. Compare list :: :: (int, [variable]) - & gt; (IT, [four]) - & gt; Sequence comparison entry (i1, s1) (i2, s2). Len1 & gt; Len2 = GT - Compare the length of the first wire. Len1 & lt; Len2 = LT | I1 & lt; I2 = GT - If they are equal, then compare the index. I2 & gt; I1 = LT - (note the opposite order, because you want the lowest index). Otherwise = EQ where len1 = length s1 len2 = length s2 is the longest = compare to maximum central  

It can be written in a less but less readable way.


No comments:

Post a Comment