[Haskell-beginners] Using output of head in data constuctor

Josh Friedlander joshuatfriedlander at gmail.com
Sun Jun 28 11:36:36 UTC 2020

Given the following code:

module Log where
import Control.Applicative

data MessageType = Info
                 | Warning
                 | Error Int

type TimeStamp = Int

data LogMessage = LogMessage MessageType TimeStamp String
                | Unknown String

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"

So it thinks I am giving it the *function* head, when I would like to give
it the output.

How do I fix this?

Thanks in advance,
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/beginners/attachments/20200628/02251729/attachment.html>

More information about the Beginners mailing list