
Hi, I have some trouble understanding the following function: http://lpaste.net/350771 If someone can take the time and explain the part after WHERE clause that would be great since I kind of know what the function does but have problems with the param order for the go anonymous function. Thanks, Sasa { name: Bogicevic Sasa phone: +381606006200 }

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

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@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@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners

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
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
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@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
_______________________________________________ Beginners mailing list Beginners@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
participants (3)
-
Daniel Trstenjak
-
sasa bogicevic
-
Vale Cofer-Shabica