[Haskell-beginners] fnc explanation
sasa bogicevic
brutallesale at gmail.com
Mon Jan 2 22:59:36 UTC 2017
Thanks!
I had to look at it multiple times to get it but it is clear now. It is still not intuitive for me since I come from imperative language world but I guess time heals all :)
Thanks once again!
Sasa
Sasa Bogicevic
{
phone: +381606006200
}
> On Jan 2, 2017, at 22:21, Vale Cofer-Shabica <vale.cofershabica at gmail.com> wrote:
>
> Hi Sasa,
>
> It might also help to look at the type of foldr:
> foldr :: Foldable t => (a -> b -> b) -> b -> t a -> b
>
> The function go has type:
> go :: Ord a => a -> (Maybe a, Bool) -> (Maybe a, Bool)
>
> The tuple, initially (Nothing, True), will be passed to go as its *2nd* argument; the first argument will be an element of the list. The underscore, which means match anything and throw it away, is there because we don't care about any of the other elements once we know the list is not ordered.
>
> Hope that helps,
> vale
>
>
> --
> vale cofer-shabica
> 401.267.8253
>
>> On Mon, Jan 2, 2017 at 12:20 PM, Daniel Trstenjak <daniel.trstenjak at gmail.com> wrote:
>>
>> Hi Sasa,
>>
>> > -- this confuses me, what is the _ here ? go is anonymous function, _ should stand for tuple ? and status xs from the top definition ?
>> > go _ status@(_, False) = status
>>
>> The first argument of 'go' is '_', which means it's ignored.
>>
>> The second argument is 'status@(_, False)'.
>> It's giving the tuple the name 'status' and pattern matching the tuple at once.
>>
>> If the pattern match succeeds, then the tuple named 'status' is returned by 'go'
>>
>>
>> Greetings,
>> Daniel
>> _______________________________________________
>> Beginners mailing list
>> Beginners at haskell.org
>> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>
> _______________________________________________
> Beginners mailing list
> Beginners at haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/beginners/attachments/20170102/462491f3/attachment.html>
More information about the Beginners
mailing list