[Haskell-beginners] Using output of head in data constuctor
Francesco Ariis
fa-ml at ariis.it
Sun Jun 28 11:47:09 UTC 2020
Hello Josh
Il 28 giugno 2020 alle 14:36 Josh Friedlander ha scritto:
> I want to create a log parser like this:
>
> module LogAnalysis where
> import Log
>
> parseMessage :: String -> LogMessage
> parseMessage xs
> | length(words(xs)) < 3 = Unknown xs
> | notElem(head(words(xs)) ["I", "E", "W"]) = Unknown xs
> | otherwise = LogMessage Info 3 head(words(xs))
>
> But GHC gives me "• Couldn't match type ‘[a0] -> a0’ with ‘[Char]’
> Expected type: String
> Actual type: [a0] -> a0"
I suspect `LogMessage Info 3 head(words(xs))` is the problem. This is
the same as writing
LogMessage Info 3 head (words xs)
keeping in mind how whitespace and parentheses work in Haskell. You
probably want
LogMessage Info 3 (head (words xs))
instead.
More information about the Beginners
mailing list