here are some type definitions in my program FYI:
type BitString -> String
type Plateau -> [BitString]
I have a function called:
--Extract will take a list of lists, and return the inner list of the most items. Empty list should return ["00000"]
extract::[Plateau]->Plateau
extract _ = ["00000"]
extract (x:xs)
|x==maximumBy(compare `on` length)xs=x --thanks SOF
|otherwise = extract (xs)
The problem is, no matter what i do, extract returns ["00000"]
here are some outputs from GHCI, that are working:
>plateau graycodes
[["01000"],["01010","11010","10010"],["00101"],["01101","01001"]]
this is expected, and is in the form of a [Plateau] since this is a list of lists of string.
>maximumBy(compare `on` length)(plateau graycodes)
["01010","11010","10010"]
>extract (plateau graycodes)
["00000"]
in this case, i know for sure that extract will be called with a not empty [Plateau]. But the _ part of the function is returning.
I have tried also:
extract (x:xs)
|x==[]=["00000"]
|x==[""]=["00000"]
|x==maximumBy(compare `on` length)xs=x --thanks SOF
|otherwise = extract (xs)
error: List.maximumBy: Empty list
you are getting that error, because you are not passing in your list
(x:xs)to maximumBy:or, preferably,
(this also adds a needed
=after yourotherwise)EDIT:
I was not satisfied with my answer, or your acceptance of that answer.
I believe this is the code you are really after: