Ich möchte ein Programm erstellen, das das Auftreten aller Elemente in einer Liste zählt und die maximale Sequenz zurückgibt. Ich habe ein Problem mit meinem Eingabeteil.Haskell Konnte den Typ 'String -> [Int]' nicht mit '[a0]' vergleichen
Die Eingabe besteht aus mehreren Testfällen. Jeder Testfall beginnt mit einer Zeile, die zwei ganze Zahlen n und q enthält (1 ≤ n, q ≤ 100000). Die nächste Zeile enthält n Ganzzahlen a1, ..., an (-100000 ≤ ai ≤ 100000
Ich möchte readNQ erhalten n und q als [int] dann übergeben, um readArray, die n Element lesen und zu [int zuweisen ] wie folgt
module Main where
import Text.Printf
import Data.List
main :: IO()
main = interact (showResults . maxSeqLength . readArray. readNQ)
readNQ :: String -> [Int]
readNQ = take 2 . (map read) . words
readArray :: [Int] -> String -> [Int]
readArray (n:xs) = take n . (map read) . words
showResults :: Int -> String
showResults x = printf "\n %d" x
maxSeqLength :: Eq a => [a] -> Int
maxSeqLength [] = 0
maxSeqLength xs = (maximum . map length . group) xs
ist jedoch ein Fehler
frequent.hs. 13: 47: Fehler:
• Couldn't match type ‘String -> [Int]’ with ‘[a0]’
Expected type: String -> [a0]
Actual type: String -> String -> [Int]
• Probable cause: ‘(.)’ is applied to too few arguments
In the second argument of ‘(.)’, namely ‘readArray . readNQ’
In the second argument of ‘(.)’, namely
‘maxSeqLength . readArray . readNQ’
In the first argument of ‘interact’, namely
‘(showResults . maxSeqLength . readArray . readNQ)’
was mit der Art der readNQ und readarray ist falsch