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: A better way? (Heinrich Apfelmus)
2. Re: Getting into nested monad transformers (Brent Yorgey)
3. desugaring an example from RWH (Michael Easter)
4. Re: desugaring an example from RWH (Andrew Wagner)
5. the ($) function (was desugaring an example from RWH)
(Michael Easter)
6. Re: the ($) function (was desugaring an example from RWH)
(Andrew Wagner)
7. Re: Re: the ($) function (was desugaring an example from
RWH) (Peter Verswyvelen)
----------------------------------------------------------------------
Message: 1
Date: Mon, 23 Feb 2009 11:54:02 +0100
From: Heinrich Apfelmus <[email protected]>
Subject: [Haskell-beginners] Re: A better way?
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=ISO-8859-1
Daniel Fischer wrote:
>
>> I'd use bang patterns in favor of the now outdated
>>
>> | x `seq` False = undefined
>>
>> pattern though.
>
> I would, too, but they're not yet portable, are they?
> Which implementations other than GHC currently support them?
No, they're not portable yet, but they're really convenient. :D The
implementations other than GHC will probably pick up -XBangPatterns as well.
Regards,
apfelmus
--
http://apfelmus.nfshost.com
------------------------------
Message: 2
Date: Mon, 23 Feb 2009 06:06:43 -0500
From: Brent Yorgey <[email protected]>
Subject: Re: [Haskell-beginners] Getting into nested monad
transformers
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=us-ascii
On Thu, Feb 19, 2009 at 09:51:06PM -0800, Arthur Chan wrote:
> Hey all,
>
> I've been trying to access the inner state "s" for this type:
>
> newtype TestThingey s a = TestThingey {
> runTrans :: ReaderT Int (StateT String (StateT s IO)) a
> } deriving (Monad, MonadIO, MonadState String, MonadReader Int)
In this situation I would combine the String and s into one state:
ReaderT Int (StateT (String,s) IO) a
Otherwise, yes, you'll just have to use the appropriate number of
lifts.
-Brent
------------------------------
Message: 3
Date: Mon, 23 Feb 2009 08:33:40 -0600
From: Michael Easter <[email protected]>
Subject: [Haskell-beginners] desugaring an example from RWH
To: [email protected]
Message-ID:
<[email protected]>
Content-Type: text/plain; charset="iso-8859-1"
Folks,
I have an example of the do-syntax that I would like to desugar. It is an
example from Chapter 28 in RWH.
I think I understand the ideas behind the following STM example, but I would
like to present it to others in a desugared way:
tryBogusSale = do
players@(alice:bob:_) <- atomically populateWorld
atomically $ alwaysSucceeds =<< consistentBalance players
bogusSale Wand 5 alice bob
I'm having problems especially with the 2nd line in the do block (i.e. the
predicate for alwaysSucceeds). I would like to try and express this in
terms of only bind (->) and return.
thanks!
Michael
--
----------------------
Michael Easter
http://codetojoy.blogspot.com: Putting the thrill back in blog
http://youtube.com/ocitv -> Fun people doing serious software engineering
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
http://www.haskell.org/pipermail/beginners/attachments/20090223/ed207ffd/attachment-0001.htm
------------------------------
Message: 4
Date: Mon, 23 Feb 2009 09:40:37 -0500
From: Andrew Wagner <[email protected]>
Subject: Re: [Haskell-beginners] desugaring an example from RWH
To: Michael Easter <[email protected]>
Cc: [email protected]
Message-ID:
<[email protected]>
Content-Type: text/plain; charset="iso-8859-1"
Here's my attempt (without a typechecker):tryBogusSale = atomically
populateWorld >>= \players@(alice:bob:_) ->
atomically (consistentBalance players >>=
alwaysSucceeds) >>
bogusSale Wand 5 alice bob
On Mon, Feb 23, 2009 at 9:33 AM, Michael Easter <[email protected]> wrote:
>
> Folks,
>
> I have an example of the do-syntax that I would like to desugar. It is an
> example from Chapter 28 in RWH.
>
> I think I understand the ideas behind the following STM example, but I
> would like to present it to others in a desugared way:
>
> tryBogusSale = do
> players@(alice:bob:_) <- atomically populateWorld
> atomically $ alwaysSucceeds =<< consistentBalance players
> bogusSale Wand 5 alice bob
>
> I'm having problems especially with the 2nd line in the do block (i.e. the
> predicate for alwaysSucceeds). I would like to try and express this in
> terms of only bind (->) and return.
>
> thanks!
> Michael
>
> --
> ----------------------
> Michael Easter
> http://codetojoy.blogspot.com: Putting the thrill back in blog
>
> http://youtube.com/ocitv -> Fun people doing serious software engineering
>
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://www.haskell.org/mailman/listinfo/beginners
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
http://www.haskell.org/pipermail/beginners/attachments/20090223/9c156025/attachment-0001.htm
------------------------------
Message: 5
Date: Mon, 23 Feb 2009 12:18:19 -0600
From: Michael Easter <[email protected]>
Subject: [Haskell-beginners] the ($) function (was desugaring an
example from RWH)
To: Andrew Wagner <[email protected]>
Cc: [email protected]
Message-ID:
<[email protected]>
Content-Type: text/plain; charset="iso-8859-1"
re: desugaring. Thanks Andrew, that worked great!
I have another, easier question from the same code in RWH:
bogusTransfer qty fromBal toBal = do
fromQty <- atomically $ readTVar fromBal
[snip]
Can someone please explain the ($) function in English? From the type
signature, it seems to be an "apply function", but I can't quite explain
when we use it. Clearly, it is used throughout RWH but I haven't found a
good explanation.
My guess is that it is when we want an "execution" of a function rather than
a mere reference to it. Is that accurate?
thanks again
Michael
--
----------------------
Michael Easter
http://codetojoy.blogspot.com: Putting the thrill back in blog
http://youtube.com/ocitv -> Fun people doing serious software engineering
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
http://www.haskell.org/pipermail/beginners/attachments/20090223/12b940d4/attachment-0001.htm
------------------------------
Message: 6
Date: Mon, 23 Feb 2009 13:27:01 -0500
From: Andrew Wagner <[email protected]>
Subject: [Haskell-beginners] Re: the ($) function (was desugaring an
example from RWH)
To: Michael Easter <[email protected]>
Cc: [email protected]
Message-ID:
<[email protected]>
Content-Type: text/plain; charset="iso-8859-1"
The $ function is essentialy a "no-op". That is, it literally does nothing.
There is no difference in Haskell between a function and a reference to it.
The only purpose of $ is for grouping. The line in question below could have
been written identically as "fromQty <- atomically (readTVar fromBal)". The
$ groups together everything to the end of the line, and can be used to
avoid parentheses that could add noise to the code.
On Mon, Feb 23, 2009 at 1:18 PM, Michael Easter <[email protected]> wrote:
>
> re: desugaring. Thanks Andrew, that worked great!
>
> I have another, easier question from the same code in RWH:
>
> bogusTransfer qty fromBal toBal = do
> fromQty <- atomically $ readTVar fromBal
> [snip]
>
> Can someone please explain the ($) function in English? From the type
> signature, it seems to be an "apply function", but I can't quite explain
> when we use it. Clearly, it is used throughout RWH but I haven't found a
> good explanation.
>
> My guess is that it is when we want an "execution" of a function rather
> than a mere reference to it. Is that accurate?
>
> thanks again
> Michael
>
> --
> ----------------------
> Michael Easter
> http://codetojoy.blogspot.com: Putting the thrill back in blog
>
> http://youtube.com/ocitv -> Fun people doing serious software engineering
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
http://www.haskell.org/pipermail/beginners/attachments/20090223/2834b420/attachment-0001.htm
------------------------------
Message: 7
Date: Mon, 23 Feb 2009 20:09:31 +0100
From: Peter Verswyvelen <[email protected]>
Subject: Re: [Haskell-beginners] Re: the ($) function (was desugaring
an example from RWH)
To: Andrew Wagner <[email protected]>
Cc: [email protected], Michael Easter <[email protected]>
Message-ID:
<[email protected]>
Content-Type: text/plain; charset="iso-8859-1"
Sometimes the apply operator $ can be handy for other purposes too, e.g.
map ($ 1) [cos, sin, tan]
evaluates to
[cos $ 1, sin $ 1, tan $ 1]
which just evaluates to
[cos 1, sin 1, tan 1]
Note that some consider the following as bad coding style:
f $ g $ h $ x
Instead, the following is preferred
f . g . h $ x
On Mon, Feb 23, 2009 at 7:27 PM, Andrew Wagner <[email protected]>wrote:
> The $ function is essentialy a "no-op". That is, it literally does nothing.
> There is no difference in Haskell between a function and a reference to it.
> The only purpose of $ is for grouping. The line in question below could have
> been written identically as "fromQty <- atomically (readTVar fromBal)". The
> $ groups together everything to the end of the line, and can be used to
> avoid parentheses that could add noise to the code.
>
>
> On Mon, Feb 23, 2009 at 1:18 PM, Michael Easter <[email protected]>wrote:
>
>>
>> re: desugaring. Thanks Andrew, that worked great!
>>
>> I have another, easier question from the same code in RWH:
>>
>> bogusTransfer qty fromBal toBal = do
>> fromQty <- atomically $ readTVar fromBal
>> [snip]
>>
>> Can someone please explain the ($) function in English? From the type
>> signature, it seems to be an "apply function", but I can't quite explain
>> when we use it. Clearly, it is used throughout RWH but I haven't found a
>> good explanation.
>>
>> My guess is that it is when we want an "execution" of a function rather
>> than a mere reference to it. Is that accurate?
>>
>> thanks again
>> Michael
>>
>> --
>> ----------------------
>> Michael Easter
>> http://codetojoy.blogspot.com: Putting the thrill back in blog
>>
>> http://youtube.com/ocitv -> Fun people doing serious software engineering
>>
>
>
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://www.haskell.org/mailman/listinfo/beginners
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
http://www.haskell.org/pipermail/beginners/attachments/20090223/ed10b885/attachment.htm
------------------------------
_______________________________________________
Beginners mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/beginners
End of Beginners Digest, Vol 8, Issue 22
****************************************