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

Josh Friedlander joshuatfriedlander at gmail.com
Sun Jun 28 12:50:20 UTC 2020


Thanks Francesco, that works. I don't quite understand what the issue was,
though. Specifically:
- Did the parentheses around (xs) hurt, or were they just redundant?
- Wouldn't the parentheses around (head ...) be binding it as an argument
to whatever comes before (in this case, 3)?

On Sun, 28 Jun 2020 at 14:47, Francesco Ariis <fa-ml at ariis.it> wrote:

> 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.
> _______________________________________________
> Beginners mailing list
> Beginners at haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/beginners/attachments/20200628/ed66b91e/attachment.html>


More information about the Beginners mailing list