Send Beginners mailing list submissions to
        beginners@haskell.org

To subscribe or unsubscribe via the World Wide Web, visit
        http://www.haskell.org/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. Re:  forall confusion (Brandon S. Allbery KF8NH)
   2. Re:  forall confusion (Isaac Dupree)
   3.  Re: forall confusion (Heinrich Apfelmus)
   4.  Arrow (Luca Ciciriello)
   5. Re:  Arrow (Brent Yorgey)
   6. Re:  Arrow (Luca Ciciriello)


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

Message: 1
Date: Sat, 29 May 2010 14:43:39 -0400
From: "Brandon S. Allbery KF8NH" <allb...@ece.cmu.edu>
Subject: Re: [Haskell-beginners] forall confusion
To: haskell-beginn...@foo.me.uk
Cc: Beginners@haskell.org
Message-ID: <8771efda-e994-4cbb-8249-2e2f91e31...@ece.cmu.edu>
Content-Type: text/plain; charset="us-ascii"

On May 29, 2010, at 11:35 , Philip Scott wrote:
> Hi all,
>
> I was wondering if someone could give me an intuitive explanation of  
> why in
>
> f :: forall a.(Show a) => a -> String
> f x = show x
>
> "forall a.(Show a) => a" appears to translate into "Any a, as long  
> as it is an instance of Show"
>
> but if I use forall in an type qualifier in an assignment:
>
> myList = [] :: [forall a.(Show a) => a]
>
> "forall a.(Show a) => a" seems to mean "Any a, as long as it is  
> bottom"


Using the WikiBook's DataBox type as an example:

In the case of [DataBox], I can build list elements with SB (a valid  
value for a [Databox] is [SB 1]); what name do I use in place of SB  
for the anonymous forall-ed type in myList?  Since I don't have such a  
name, the only possible value I can use is the one value that exists  
in every type:  bottom.

Other examples:

     f :: forall a. (Show a) => a -> String -- your example above

versus

     undefined :: forall a. a -- from the Haskell Prelude

This highlights a corner case:  "f" gives you a "nickname" to use,  
namely the fact that the forall-ed type is an argument.  "undefined"  
doesn't give you any handle at all, so its only possible value is  
bottom.


     data ST s a
     runST :: (forall s. ST s a) -> a

runST gives you a temporary name for "a", in the form of the returned  
value.  You don't have a name for the "s", though, as it's hidden  
inside the ST type, which doesn't have any constructors.  This is used  
to hide information:  the invocation "runST myFunc initialValue"  
invokes myFunc, passing it initialValue and a special container whose  
contents are private (the "s").  myFunc can put things into and take  
things out of the container, using the functions in Control.Monad.ST,  
and having taken a value out it can pass that value to something else  
--- but nothing outside of the definition of myFunc can get at the  
container.  This is mainly useful when you need to hide an impure  
manipulation of values:  you can do destructive updates of things  
inside the container, as long as any given input to myFunc always  
produces the same output (referential transparency:  it should always  
be possible to replace a function call with its result, meaning it  
can't depend on external state other than its parameters).  A fast  
array library can use runST to perform a destructive-update algorithm  
when it's faster than the equivalent pure algorithm, provided both  
algorithms always produce the same results for the same inputs.

-- 
brandon s. allbery [solaris,freebsd,perl,pugs,haskell] allb...@kf8nh.com
system administrator [openafs,heimdal,too many hats] allb...@ece.cmu.edu
electrical and computer engineering, carnegie mellon university    KF8NH


-------------- next part --------------
A non-text attachment was scrubbed...
Name: PGP.sig
Type: application/pgp-signature
Size: 195 bytes
Desc: This is a digitally signed message part
Url : 
http://www.haskell.org/pipermail/beginners/attachments/20100529/3d87e212/PGP-0001.bin

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

Message: 2
Date: Sat, 29 May 2010 16:30:25 -0400
From: Isaac Dupree <m...@isaac.cedarswampstudios.org>
Subject: Re: [Haskell-beginners] forall confusion
To: Beginners@haskell.org
Message-ID: <4c017961.7040...@isaac.cedarswampstudios.org>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed

On 05/29/10 11:35, Philip Scott wrote:
> Hi all,
>
> I was wondering if someone could give me an intuitive explanation of why in
>
> f :: forall a.(Show a) => a -> String
> f x = show x
>
> "forall a.(Show a) => a" appears to translate into "Any a, as long as it
> is an instance of Show"

The function must be type-correctly defined for "any a in Show".  (the 
caller/user "chooses" which type "a" is desired.)

> but if I use forall in an type qualifier in an assignment:
>
> myList = [] :: [forall a.(Show a) => a]

Each element of this list must be "any a in Show".  (the caller/user 
"chooses" which type "a" is desired.)  In this case, the only way to 
generate a value that is truly "any a in Show" is "undefined".*

*some classes, like Read, might provide another possible value, as in 
[read "123"] which could be [forall a.(Read a) => a] -- albeit only a 
few types "a", such as Integer and Double, would actually have 
non-bottom values in this case, but it's easy to construct less-awful 
examples.

Why were you poring over Existentially Quantified Types? -- you didn't 
use any existentials above -- did you want to? (or I should ask -- can 
you tell, yet, whether you wanted to?)

-Isaac


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

Message: 3
Date: Sun, 30 May 2010 09:53:44 +0200
From: Heinrich Apfelmus <apfel...@quantentunnel.de>
Subject: [Haskell-beginners] Re: forall confusion
To: beginners@haskell.org
Message-ID: <htt5i8$uc...@dough.gmane.org>
Content-Type: text/plain; charset=UTF-8

Philip Scott wrote:
> I've been poring over
> 
> http://en.wikibooks.org/wiki/Haskell/Existentially_quantified_types
> 
> for the last hour and I feel like my eyes are starting to melt.

  http://en.wikibooks.org/wiki/Haskell/Polymorphism

is also relevant.


Regards,
Heinrich Apfelmus

--
http://apfelmus.nfshost.com



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

Message: 4
Date: Sun, 30 May 2010 16:14:27 +0200
From: Luca Ciciriello <luca_cicirie...@hotmail.com>
Subject: [Haskell-beginners] Arrow
To: beginners@haskell.org
Message-ID: <blu0-smtp972f3e13257c7b0d90dcbb9a...@phx.gbl>
Content-Type: text/plain; charset=us-ascii

Hi All.
As a mathematician I've studied the Arrows calculus as extension of the lambda 
calculus. Now I've found in the Haskell programming language that there is a 
library named Control.Arrow.  I've read  on Haskell wiki that Control.Arrow is 
a generalization of monads. So, is that library related in same way with the 
Arrows calculus?

Thanks in advance for any answer.

Luca.

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

Message: 5
Date: Sun, 30 May 2010 10:41:56 -0400
From: Brent Yorgey <byor...@seas.upenn.edu>
Subject: Re: [Haskell-beginners] Arrow
To: beginners@haskell.org
Message-ID: <20100530144155.ga...@seas.upenn.edu>
Content-Type: text/plain; charset=us-ascii

What do you mean by the Arrows calculus?  Can you give a link?  If you
mean Lindley, Wadler, and Yallop's work, then yes, that is directly
related to Control.Arrow.  If you mean some other formalism with the
same name, then I'm not sure.

-Brent

On Sun, May 30, 2010 at 04:14:27PM +0200, Luca Ciciriello wrote:
> Hi All.
> As a mathematician I've studied the Arrows calculus as extension of the 
> lambda calculus. Now I've found in the Haskell programming language that 
> there is a library named Control.Arrow.  I've read  on Haskell wiki that 
> Control.Arrow is a generalization of monads. So, is that library related in 
> same way with the Arrows calculus?
> 
> Thanks in advance for any answer.
> 
> Luca._______________________________________________
> Beginners mailing list
> Beginners@haskell.org
> http://www.haskell.org/mailman/listinfo/beginners


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

Message: 6
Date: Sun, 30 May 2010 16:53:46 +0200
From: Luca Ciciriello <luca_cicirie...@hotmail.com>
Subject: Re: [Haskell-beginners] Arrow
To: Brent Yorgey <byor...@seas.upenn.edu>
Cc: beginners@haskell.org
Message-ID: <blu0-smtp41da69c275280a37b65efc9a...@phx.gbl>
Content-Type: text/plain; charset=us-ascii

Yes, I read the article "The arrow calculus" in the Journal of Functional 
Programming in January.

http://journals.cambridge.org/action/displayIssue?jid=JFP&volumeId=20&seriesId=0&issueId=01

Thanks for your answer.

Luca.


On May 30, 2010, at 4:41 PM, Brent Yorgey wrote:

> What do you mean by the Arrows calculus?  Can you give a link?  If you
> mean Lindley, Wadler, and Yallop's work, then yes, that is directly
> related to Control.Arrow.  If you mean some other formalism with the
> same name, then I'm not sure.
> 
> -Brent
> 
> On Sun, May 30, 2010 at 04:14:27PM +0200, Luca Ciciriello wrote:
>> Hi All.
>> As a mathematician I've studied the Arrows calculus as extension of the 
>> lambda calculus. Now I've found in the Haskell programming language that 
>> there is a library named Control.Arrow.  I've read  on Haskell wiki that 
>> Control.Arrow is a generalization of monads. So, is that library related in 
>> same way with the Arrows calculus?
>> 
>> Thanks in advance for any answer.
>> 
>> Luca._______________________________________________
>> Beginners mailing list
>> Beginners@haskell.org
>> http://www.haskell.org/mailman/listinfo/beginners
> 



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

_______________________________________________
Beginners mailing list
Beginners@haskell.org
http://www.haskell.org/mailman/listinfo/beginners


End of Beginners Digest, Vol 23, Issue 44
*****************************************

Reply via email to