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

Roelof Wobben r.wobben at home.nl
Mon Nov 10 18:59:01 UTC 2014


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
>>
>>
>>
>
>



More information about the Beginners mailing list