This is simply a precedence problem. Judicious use of parentheses will solve it.<br><br><div class="gmail_quote">On Mon Nov 10 2014 at 16:32:36 Roelof Wobben <<a href="mailto:r.wobben@home.nl">r.wobben@home.nl</a>> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Stefan Höck schreef op 10-11-2014 17:18:<br>
>> I try to say that if the input list has only 1 item the outcome is the head<br>
>> of that list.<br>
> This is not how one typically thinks about folds. Look at the type of<br>
> acc:<br>
><br>
>    acc :: a -> Maybe a -> Maybe a<br>
><br>
> acc is a function wich takes two arguments (ignoring currying): On is of<br>
> type `a`. This is the element type of the list you fold over. The other<br>
> is of type `Maybe a`. This is the value you accumulate in your fold.<br>
> The initial value is `Nothing`. You start your fold literally with<br>
> nothing, since you haven't visited any element in the list yet. Now the<br>
> first element of the list (see below) is passed to acc. What do you do<br>
> with it?<br>
><br>
>    acc a Nothing = ???<br>
><br>
> a is an element in your lit, Nothing is the value you have accumulated<br>
> so far. What do you do? Ignore a? Keep it? If you ignore a, you return<br>
> `Nothing`.<br>
><br>
>    acc a Nothing = Nothing<br>
><br>
> With this accumulator, the list will be traversed (ignoring lazy<br>
> evaluation for the time being), all values will be<br>
> ignored and your result will be Nothing, no matter what kind of list you<br>
> fold over. Therefore, let's keep value `a`. In order to do that, we have<br>
> to wrap it in a Just, otherwise the types won't match:<br>
><br>
>    acc a Nothing = Just a<br>
><br>
> This function will give the right result for empty lists (Nothing) and<br>
> for lists with a single value where the value is wrapped in a Just. The<br>
> function will throw an error however, if you pass it a list containing<br>
> more than one element, because the pattern match is not exhaustive.<br>
> We need to decide what happens, when we already have a<br>
> value wrapped in a Just:<br>
><br>
>    acc a Just b = ???<br>
><br>
><br>
<br>
It makes sence except when I enter acc a Just B I see this error message :<br>
ConstructorJustshould have 1 argument, but has been given none…<br>
______________________________<u></u>_________________<br>
Beginners mailing list<br>
<a href="mailto:Beginners@haskell.org" target="_blank">Beginners@haskell.org</a><br>
<a href="http://www.haskell.org/mailman/listinfo/beginners" target="_blank">http://www.haskell.org/<u></u>mailman/listinfo/beginners</a><br>
</blockquote></div>