[Haskell-beginners] fnc explanation

Vale Cofer-Shabica vale.cofershabica at gmail.com
Mon Jan 2 21:21:31 UTC 2017


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
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/beginners/attachments/20170102/761188bd/attachment.html>


More information about the Beginners mailing list