Send Beginners mailing list submissions to
        beginners@haskell.org

To subscribe or unsubscribe via the World Wide Web, visit
        http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
or, via email, send a message with subject or body 'help' to
        beginners-requ...@haskell.org

You can reach the person managing the list at
        beginners-ow...@haskell.org

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."


Today's Topics:

   1.  fnc explanation (sasa bogicevic)
   2. Re:  fnc explanation (Daniel Trstenjak)
   3. Re:  fnc explanation (Vale Cofer-Shabica)
   4. Re:  fnc explanation (sasa bogicevic)


----------------------------------------------------------------------

Message: 1
Date: Mon, 2 Jan 2017 18:05:57 +0100
From: sasa bogicevic <brutalles...@gmail.com>
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <beginners@haskell.org>
Subject: [Haskell-beginners] fnc explanation
Message-ID: <4f6f35f4-e3fb-41fd-9ee5-bf8bd3fd2...@gmail.com>
Content-Type: text/plain; charset=us-ascii

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
}





------------------------------

Message: 2
Date: Mon, 2 Jan 2017 18:20:58 +0100
From: Daniel Trstenjak <daniel.trsten...@gmail.com>
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <beginners@haskell.org>
Subject: Re: [Haskell-beginners] fnc explanation
Message-ID: <20170102172058.GA28689@octa>
Content-Type: text/plain; charset=us-ascii


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


------------------------------

Message: 3
Date: Mon, 2 Jan 2017 16:21:31 -0500
From: Vale Cofer-Shabica <vale.cofershab...@gmail.com>
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <beginners@haskell.org>
Subject: Re: [Haskell-beginners] fnc explanation
Message-ID:
        <caazfv4q8c35ejoocbbwvgglfrpj7cbuqsnozewts2t+o-b+...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

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

------------------------------

Message: 4
Date: Mon, 2 Jan 2017 23:59:36 +0100
From: sasa bogicevic <brutalles...@gmail.com>
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <beginners@haskell.org>
Subject: Re: [Haskell-beginners] fnc explanation
Message-ID: <1e922df6-0379-4ebf-b82d-c2da57d30...@gmail.com>
Content-Type: text/plain; charset="utf-8"

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.cofershab...@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.trsten...@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
> 
> _______________________________________________
> Beginners mailing list
> Beginners@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-0001.html>

------------------------------

Subject: Digest Footer

_______________________________________________
Beginners mailing list
Beginners@haskell.org
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners


------------------------------

End of Beginners Digest, Vol 103, Issue 1
*****************************************

Reply via email to