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: Large binary overhead? (Christopher Howard)
2. Re: how does the State monad actually work? (Aleksandar Dimitrov)
----------------------------------------------------------------------
Message: 1
Date: Wed, 25 May 2011 21:04:58 -0800
From: Christopher Howard <[email protected]>
Subject: Re: [Haskell-beginners] Large binary overhead?
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=ISO-8859-1
On 05/25/2011 08:02 PM, Erik de Castro Lopo wrote:
> Christopher Howard wrote:
>
>> I'm still going through the GHC tutorial, so be patient with me: But why
>> is it that my GHC-produced executables are always so large? Even my one
>> line Hello World program ends up being over 500KB. I thought maybe it
>> was because all of the functionality was statically compiled in, but I
>> used ldd and saw that my hello world binary links dynamically to 10
>> different C libraries.
>
> Its that size because the Haskell libraries are statically linked
> into your program.
>
> See this SO question/answer:
>
>
> http://stackoverflow.com/questions/6115459/small-haskell-program-compiled-with-ghc-into-huge-binary
>
> Erik
Thanks! Great link! I only wish I had known about that sooner... It
looks like I'll need to reinstall at least a few dozen modules with
--enabled-shared. I'm surprised that cabal-install doesn't enable that
by default.
--
frigidcode.com
theologia.indicium.us
------------------------------
Message: 2
Date: Thu, 26 May 2011 11:23:45 +0200
From: Aleksandar Dimitrov <[email protected]>
Subject: Re: [Haskell-beginners] how does the State monad actually
work?
To: Benjamin Edwards <[email protected]>
Cc: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset="utf-8"
On Tue, May 24, 2011 at 9:50 AM, Benjamin Edwards <[email protected]>wrote:
> I highly recommend reading some of the tutorials that show how to derive
> the state monad. The type of state is really a function that takes a
> parameter and returns a state tupled with a value. Yet another haskell
> tutorial has quite a good chapter on this.
>
Personally, I think one should have a look at the "Monads" chapter in RWH,
and maybe also LYAH. Here are the respective links:
http://book.realworldhaskell.org/read/monads.html#monads.state and
http://learnyouahaskell.com/for-a-few-monads-more#state (also take a look at
the preceding chapter in LYAH, since it introduces Monads more generally.)
> I get "blah" as expected. When I switch to execState I get the value 1.
> This is what confuses me. Where is the State coming from if it is not passed
> into foo? What are get and put operating on?
>
> get does not need a parameter. It executes in the state monad, and get is
defined to retrieve the computation's enclosing state. Put *does* take a
parameter, and that is the new state for the state monad. Mind you, the
state is not *implicit* -- it is, in fact, made explicit in the type
signature; but it looks as if it were implicit in the definition of your
function. In any case, you do not need to supply the value of the state to
either get or put as a parameter, because both are designed around chaining
stateful computations together without passing around the state in the
function's arguments!
execState and runState just do different things. Look at the type signatures
using hoogle:
execState :: State s a -> s -> s
runState :: State s a -> s -> (a, s)
evalState :: State s a -> s -> a
State itself is defined as a tuple of state and result. runState is the
function you use to retrieve both. evalState and execState just produce
special cases of runState (i.e. they retrieve either one or the other member
of the tuple.)
HTH,
Aleks
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://www.haskell.org/pipermail/beginners/attachments/20110526/64bf36be/attachment-0001.htm>
------------------------------
_______________________________________________
Beginners mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/beginners
End of Beginners Digest, Vol 35, Issue 50
*****************************************