[Haskell-cafe] how to make this work recursive ?

ok at cs.otago.ac.nz ok at cs.otago.ac.nz
Mon Mar 2 09:57:42 UTC 2015

You are still not being clear.
You have

    data LogMessage
       = LogMessage MessageType TimeStamp String
       | Unknown                          String
       deriving (Show, Eq)

> So if it's Unknown with a string then it will not be inserted into the
> MessageTree
> The only thing I have to find out if  LogMessage contains this.

Question 1.
    Your description seems contradictory.
    The first sentence is talking about the Unknown case.
    The second sentence appears to be talking about the other
    Do you mean

       should_discard (LogMessage _ _ _) = False
       should_discard (Unknown s) = ...s contains magic...


       should_discard (LogMessage _ _ s) = ...s contains magic...
       should_discard (Unknown _) = False


       should_discard (LogMessage Error _ s) = ...s contains magic...
       should_discard _ = False

    or what?

Question 2.

    What do you mean by "contains"?
    Do you mean
       - is exactly equal to
       - is equal to ignoring leading and trailing white space
         and treating runs of white space as single spaces
       - is equal to ignoring alphabetic case
       - equality up to some other predicate
       - contains a substring equal to
         (this is what I first thought you meant)
       - contains a substring equivalent to up to some predicate
    or something else?

In short, before you can ask how to do "this",
you have to say in plain words what "this" IS.

The _answer_ will be concerned with Haskell,
but _the way you should ask such questions_ is not.

In any programming language, whatever code you write is going to
have *some* precise meaning.  The industry as a whole has a huge
problem with differences between what people *want* their
program to mean/do and what it *does* mean/do.  We haven't a hope
of detecting such problems in good time if we aren't clear about
what it is that we want.

Here's another tip.  Some people find it helps.

Before you start to write a function, just write a stub (others
have shown you examples, using 'undefined' as the body; that's
a stub), and write test cases that call it.  This may help to
clarify your ideas about what you want the function to do with
_those_ examples, and thereby about others.

More information about the Haskell-Cafe mailing list