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

Roelof Wobben r.wobben at home.nl
Mon Mar 2 08:23:09 UTC 2015


Richard A. O'Keefe schreef op 2-3-2015 om 0:49:
> On 1/03/2015, at 2:39 am, Roelof Wobben <r.wobben at home.nl> wrote:
>
>> I tried this :
>>
>> insert :: LogMessage -> MessageTree -> MessageTree
>> insert s =
>>     case words s of
>>         (_:_: "This is not the right format") -> MessageTree Leaf
>>         _                                     -> MessageTree Node LogMessage Leaf
> This makes no sense.
> You have declared that insert takes a LogMessage argument
> and a MessageTree argument and returns a MessageTree result.
>
> Then your code DOES NOT ACCEPT A MESSAGETREE ARGUMENT!
>
> You want to have
>
> insert logmsg msgtree =
>
> and the case analysis should be on the message tree, not the log message.
>
> src/LogAnalysis.hs at 38:49-38:60
>> Not in scope: data constructor
>> MessageTree
>> src/LogAnalysis.hs at 39:49-39:60
>> Not in scope: data constructor
>> MessageTree
> The compiler is telling you, as clearly as it knows how,
> that you DO NOT HAVE ANY CONSTRUCTOR FUNCTION called "MessageTree".
> The constructor functions are >> Leaf << and >> Node <<.
> MessageTree is a *TYPE NAME*.
>
>
> I am about to be offensive.
> I do not want to be offensive.
> I want to be helpful.
> I believe this question needs to be asked.
> But there is a real risk that I will offend you.
>
> Here goes.
>
> Is there *any* programming language you know how to use?
>
> The reason that I ask is that the problems you keep having
> aren't really Haskell problems.  They are general programming
> problems:
>   - declaring a name as one kind of thing
>     and using it as if it were another
>   - declaring a function (like 'insert' or 'Node')
>     to have n arguments but trying to define or call
>     it with m arguments where m ~= n.
>   - not starting with a description of your problem
>   - not having a clue what to do when the compiler tells
>     you something.  (It's OK not to understand a
>     compiler message.  But you should get *some* clue
>     from it, like where exactly to look, and you should
>     be able to try to vary the program to see how the
>     message changes.)
>
> I honestly feel that the difficulties you are reporting here
> aren't really Haskell difficulties, just as the difficulties
> you were reporting in the Erlang mailing list weren't really
> Erlang difficulties, but in both cases, something much more
> fundamental.
>
> To restate my possibly offensive question again:
>
> Have you ever had a course of instruction in the use of
> any programming language face to face with a competent
> teacher?
>
> Again, I'm trying to be helpful here.  If you run into a
> problem and can get help within *minutes*, and have someone
> sit down beside you at the keyboard and *show* you how to
> find out what a compiler message might mean and what to do
> about it, you can learn very quickly.  If you have to wait
> hours for responses, you are obviously going to learn much
> more slowly.
>
> I sometimes ask my students: "What's the point of coming here?
> Why not just buy a textbook?"  Sadly, they sometimes do not
> know the answer.  It's "You can ask ME questions, and each other."
>
> It is clear that you are working at trying to learn Haskell.
> It is SMART of you to ask questions.
> It's just that there are these really basic issues where I
> think you could learn a lot faster with face-to-face help.
>
>
>


I have not done any face to face courses.
Programming is a hobby for me.

Roelof



More information about the Haskell-Cafe mailing list