[Haskell-beginners] Are these soloutions all valid and a good use of Haskell

Julian Birch julian.birch at gmail.com
Mon Nov 10 19:50:05 UTC 2014


Me misunderstanding actually.  I'd forgotten the foldr.  The answer is that
foldr calls your folding function multiple times, do you don't need to
worry about it.

On Monday, November 10, 2014, Roelof Wobben <r.wobben at home.nl> wrote:

>  Julian Birch schreef op 10-11-2014 20:41:
>
>
> Consider what happens if you apply the last function to xs.
>
>
> Then you get the last item but fold supposes to run over all items.
>
> Or do I misunderstood the question.
>
> Roelof
>
>
>
>
>  On Monday, November 10, 2014, Roelof Wobben <r.wobben at home.nl
> <javascript:_e(%7B%7D,'cvml','r.wobben at home.nl');>> wrote:
>
>> Of course the compiler is right.
>>
>> Im still struggeling.
>>
>> What I try to do is this
>>
>> 1) if acc is empty then a empty list so the output must be Nothing
>> 2) if the input has only one item then it is the last so the output must
>> be that item.
>> 3) if the input has more then 1item then the last item is not reached so
>> acc must have the value of the next item of the input file
>>
>> And I do not see how I can give acc the value of the next value of the
>> input file maybe head xs
>>
>> Roelof
>>
>>
>> Leza Morais Lutonda schreef op 10-11-2014 19:52:
>>
>>> Hi Roelof,
>>>
>>> On 10/11/14 10:10, Roelof Wobben wrote:
>>>
>>>> No problem .
>>>>
>>>> Im strugelling to make acc work.
>>>>
>>>> I try to say that if the input list has only 1 item the outcome is the
>>>> head of that list.
>>>> But doing
>>>>
>>>> acc = Just (head a)  or doing acc = Just (head acc) gives both that acc
>>>> or a is not in scope
>>>>
>>> The `a` in the type signature `acc :: a -> Maybe a -> Maybe a` is not a
>>> variable name, it is a type.
>>>
>>>>
>>>> also doing acc x = Just (head x) gives a error messages that the types
>>>> are not matching.
>>>>
>>> :t Just (head x)
>>> Maybe a
>>>
>>> :t acc x
>>> Maybe a -> Maybe a
>>>
>>> So, the compiler is right!
>>>
>>>
>>>
>>>> Roelof
>>>>
>>>>
>>>>
>>>>
>>>
>>>
>> _______________________________________________
>> Beginners mailing list
>> Beginners at haskell.org
>> http://www.haskell.org/mailman/listinfo/beginners
>>
>
>
> --
> Sent from an iPhone, please excuse brevity and typos.
>
>
> _______________________________________________
> Beginners mailing listBeginners at haskell.org <javascript:_e(%7B%7D,'cvml','Beginners at haskell.org');>http://www.haskell.org/mailman/listinfo/beginners
>
>
>

-- 
Sent from an iPhone, please excuse brevity and typos.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/beginners/attachments/20141110/c54319f5/attachment.html>


More information about the Beginners mailing list