Send Beginners mailing list submissions to
        [email protected]

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
        [email protected]

You can reach the person managing the list at
        [email protected]

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


Today's Topics:

   1. Re:  Global variables (Michael Xavier)
   2. Re:  Global variables (aditya siram)
   3. Re:  Various style at instance of a typeclass (Stephen Tetley)
   4. Re:  Why aren't David Harley's QT bindings more   popular?
      (Heinrich Apfelmus)
   5.  opengl and application state (Sean Charles)
   6.  Understanding category theory ( Christopher Howard )
   7. Re:  Understanding category theory (Jake Penton)
   8. Re:  Understanding category theory (Arlen Cuss)
   9. Re:  Global variables (Ertugrul Soeylemez)
  10. Re:  Global variables (Michael Snoyman)


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

Message: 1
Date: Wed, 29 Jun 2011 08:47:44 -0700
From: Michael Xavier <[email protected]>
Subject: Re: [Haskell-beginners] Global variables
To: [email protected]
Cc: [email protected], ARJANEN Lo?c Jean-David
        <[email protected]>
Message-ID: <[email protected]>
Content-Type: text/plain; charset="iso-8859-1"

I think my head isn't on straight this morning. I think I meant something
more along the lines of Control.Monad.State

On Wed, Jun 29, 2011 at 8:27 AM, Christopher Done
<[email protected]>wrote:

> On 29 June 2011 17:22, Michael Xavier <[email protected]> wrote:
> > I tend to use Control.Monad.Reader for stateful stuff like this. It is
> found
> > in the mtl package
> > http://hackage.haskell.org/package/mtl-2.0.1.0
>
> How would you use reader for a counter?
>



-- 
Michael Xavier
http://www.michaelxavier.net
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://www.haskell.org/pipermail/beginners/attachments/20110629/dc05ab4e/attachment-0001.htm>

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

Message: 2
Date: Wed, 29 Jun 2011 10:57:49 -0500
From: aditya siram <[email protected]>
Subject: Re: [Haskell-beginners] Global variables
To: Michael Xavier <[email protected]>
Cc: [email protected], ARJANEN Lo?c Jean-David
        <[email protected]>
Message-ID: <[email protected]>
Content-Type: text/plain; charset=ISO-8859-1

Although it is generally considered an anti-pattern, it is possible to
implement a true mutable, global counter [1] a la
every-other-imperative-language in Haskell.

As some other people have indicated you're better off with the State
monad, but this style comes in handy when you need to translate
imperative code into Haskell without having to do a complete redesign.

-deech

[1] 
http://stackoverflow.com/questions/6302249/how-to-implement-a-global-counter-using-monad/6349651#6349651

On Wed, Jun 29, 2011 at 10:47 AM, Michael Xavier
<[email protected]> wrote:
> I think my head isn't on straight this morning. I think I meant something
> more along the lines of Control.Monad.State
>
> On Wed, Jun 29, 2011 at 8:27 AM, Christopher Done <[email protected]>
> wrote:
>>
>> On 29 June 2011 17:22, Michael Xavier <[email protected]> wrote:
>> > I tend to use Control.Monad.Reader for stateful stuff like this. It is
>> > found
>> > in the mtl package
>> > http://hackage.haskell.org/package/mtl-2.0.1.0
>>
>> How would you use reader for a counter?
>
>
>
> --
> Michael Xavier
> http://www.michaelxavier.net
>
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://www.haskell.org/mailman/listinfo/beginners
>
>



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

Message: 3
Date: Wed, 29 Jun 2011 17:05:46 +0100
From: Stephen Tetley <[email protected]>
Subject: Re: [Haskell-beginners] Various style at instance of a
        typeclass
Cc: Haskell Beginer <[email protected]>
Message-ID: <[email protected]>
Content-Type: text/plain; charset=ISO-8859-1

On 29 June 2011 16:36, Haisheng Wu <[email protected]> wrote:

> Well, how did you know Monad is with kind :: * -> * ?

If I was looking at the docs I'd see these two pieces

> class Monad m where
> (>>=) :: forall a b. m a -> (a -> m b) -> m b

As (m a) and (m b) are used in the method (>>=) and but only m is
specified in the class declaration, it would tell me m is :: * -> *.


There is an extension in GHC (probably {-# LANGUAGE KindSignatures #-}
) where you can specify kinds in the class declaration:

> class Monad (m :: * -> *) where

Personally I wouldn't be upset if this was the only valid syntax -
it's redundant but I find it clearer.

I'm not sure what references are available. I think constructor
classes were originally implemented in Gofer (a Haskell variant) and
when they were in Gofer but not Haskell, people seemed to make a clear
distinction between the two. Nowadays people just call them "type
classes" and have got used to the kinds of the common classes.



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

Message: 4
Date: Wed, 29 Jun 2011 19:53:22 +0200
From: Heinrich Apfelmus <[email protected]>
Subject: Re: [Haskell-beginners] Why aren't David Harley's QT bindings
        more    popular?
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=UTF-8; format=flowed

Mats Rauhala wrote:
> Heinrich Apfelmus wrote:
>>
>> I would like to encourage you to try it out and get back to me with
>> any issues you have, both concerning documentation/learning and
>> functionality. For instance, one of the authors of Leksah has
>> experimented with it; while he had more ambitious plans than
>> reactive-banana can handle at the moment, it prompted me to come up
>> with the pleasing improvements in version 0.3. Not to mention that I
>> now have a new use case to keep in mind for the big picture.
> 
> Personally, what I'd like is a simple documented tutorial/example for a
> simple application (counter which updates a label?), which is kept
> updated even when the library updates.
> 
> I noticed two examples in the github repository, but I didn't have time
> to properly read them through yet.

Yikes, it should be much easier to find the examples. There, I have 
created a new and nice project page just now:

   http://haskell.org/haskellwiki/Reactive-banana

In particular, links to examples can be found here

   http://haskell.org/haskellwiki/Reactive-banana/Examples

Behold the screenshot!


Best regards,
Heinrich Apfelmus

--
http://apfelmus.nfshost.com




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

Message: 5
Date: Wed, 29 Jun 2011 22:34:53 +0100
From: Sean Charles <[email protected]>
Subject: [Haskell-beginners] opengl and application state
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed

How!?!?!  LOL

I am getting back into OpenGL again with Haskell now and I have a 
program that listens to all the callbacks and prints stuff out, 
terminates on Ctrl+X and draws a grey sphere. Earth shattering.

If I was using C/C++ I'd be using a (shudder) global pointer to a record 
containing state that the render callback would use to know what to do.

I smell state monads or something but I cannot see how to pass them into 
"the loop".

I want to organise my code so that all input events cause a record to be 
updated and then the render part just uses the current values to draw 
the right things, with the obvious caveat of "what if a key event 
happens half way through the render phase." MVars? Threads? What??? I'm 
a real newb on this right now!

How do I,or what is a "best practice" for passing a continuously 
changing record across calls given that the "displayCallback" doesnt 
have any obvious place to plug one on? In Erlang or even Haskell, there 
is the idion of making a tail call back to yourself with the new 
modified record and so on but I cannot figure out where to actually pass 
it around!

Thanks in advance.
Sean.




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

Message: 6
Date: Wed, 29 Jun 2011 16:26:21 -0800
From: " Christopher Howard "    <[email protected]>
Subject: [Haskell-beginners] Understanding category theory
To: " Haskell Beginners " <[email protected]>
Message-ID: <[email protected]>
Content-Type: text/plain; charset="utf-8"

Would anyone recommend a particular book or tutorial to help me understand 
category theory? I've tried reading a few tutorials i've googled, but even the 
"beginner" ones are very difficult and seem to assume a lot.

Sent from my HTC
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://www.haskell.org/pipermail/beginners/attachments/20110629/f4886d1b/attachment.htm>

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

Message: 7
Date: Wed, 29 Jun 2011 20:36:25 -0400
From: Jake Penton <[email protected]>
Subject: Re: [Haskell-beginners] Understanding category theory
To: Haskell Beginners <[email protected]>
Message-ID: <[email protected]>
Content-Type: text/plain; charset=us-ascii


On 2011-06-29, at 8:26 PM, Christopher Howard wrote:

> Would anyone recommend a particular book or tutorial to help me understand 
> category theory? I've tried reading a few tutorials i've googled, but even 
> the "beginner" ones are very difficult and seem to assume a lot.
> 

I just picked up the book by Benjamin Pierce entitled Basic Category Theory for 
Computer Scientists. It is pretty good; at least I am making some headway in 
it. I have another more recent book by Pierce called Types and Programming 
Languages, which I found to be very readable, so I am a bit of a fan of Pierce.

It is not an easy topic, IMHO. I have a B.Sc. in math, and am currently doing a 
master's degree in software engineering. I find functional programming 
literature that purports to be tutorial in nature (as opposed to research 
oriented) some of the most impenetrable stuff I have ever read. Reading it is 
like trying to eat a bowl of steam with a fork.

Good luck.





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

Message: 8
Date: Thu, 30 Jun 2011 11:06:44 +1000
From: Arlen Cuss <[email protected]>
Subject: Re: [Haskell-beginners] Understanding category theory
To: Christopher Howard <[email protected]>
Cc: Haskell Beginners <[email protected]>
Message-ID: <[email protected]>
Content-Type: text/plain; charset=UTF-8

On 30/06/2011 10:26 AM, Christopher Howard wrote:
> Would anyone recommend a particular book or tutorial to help me
> understand category theory? I've tried reading a few tutorials i've
> googled, but even the "beginner" ones are very difficult and seem to
> assume a lot.

I've just started reading this, found on /r/haskell on Reddit:

http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.78.7317&rep=rep1&type=pdf

It's quite readable, may require a little effort though!



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

Message: 9
Date: Thu, 30 Jun 2011 07:21:25 +0200
From: Ertugrul Soeylemez <[email protected]>
Subject: Re: [Haskell-beginners] Global variables
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=US-ASCII

Christopher Done <[email protected]> wrote:

> > I tend to use Control.Monad.Reader for stateful stuff like this. It
> > is found in the mtl package
> > http://hackage.haskell.org/package/mtl-2.0.1.0
>
> How would you use reader for a counter?

Reader is a good choice for an interthread counter:

    MonadIO m => ReaderT (TVar Int) m

I think, then people are talking about global variables in Haskell, what
they really want is such a thing.


Greets,
Ertugrul


-- 
nightmare = unsafePerformIO (getWrongWife >>= sex)
http://ertes.de/





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

Message: 10
Date: Thu, 30 Jun 2011 08:28:50 +0300
From: Michael Snoyman <[email protected]>
Subject: Re: [Haskell-beginners] Global variables
To: Ertugrul Soeylemez <[email protected]>
Cc: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=ISO-8859-1

On Thu, Jun 30, 2011 at 8:21 AM, Ertugrul Soeylemez <[email protected]> wrote:
> Christopher Done <[email protected]> wrote:
>
>> > I tend to use Control.Monad.Reader for stateful stuff like this. It
>> > is found in the mtl package
>> > http://hackage.haskell.org/package/mtl-2.0.1.0
>>
>> How would you use reader for a counter?
>
> Reader is a good choice for an interthread counter:
>
> ? ?MonadIO m => ReaderT (TVar Int) m
>
> I think, then people are talking about global variables in Haskell, what
> they really want is such a thing.
>
>
> Greets,
> Ertugrul

Though in this case, you can go with the cheaper IORef, since
(presumably) the only operation is going to be incrementing the
counter. Just be sure to use atomicModifyIORef[1].

Michael

[1] 
http://hackage.haskell.org/packages/archive/base/4.3.1.0/doc/html/Data-IORef.html#v:atomicModifyIORef



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

_______________________________________________
Beginners mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/beginners


End of Beginners Digest, Vol 36, Issue 83
*****************************************

Reply via email to