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. Brainfuck interpreter stack overflow (Edgar Klerks)
2. Re: Brainfuck interpreter stack overflow (Stephen Tetley)
3. Re: Brainfuck interpreter stack overflow (Daniel Fischer)
4. Re: Brainfuck interpreter stack overflow (Edgar Klerks)
5. Re: Re: testing and the culture of Haskell (David Virebayre)
6. Function nesting (Zbigniew Stanasiuk)
7. Re: Function nesting (Magnus Therning)
8. Re: Function nesting (Zbigniew Stanasiuk)
9. Re: Function nesting (Daniel Fischer)
10. Re: Re: Function nesting (Daniel Fischer)
----------------------------------------------------------------------
Message: 1
Date: Thu, 21 Jan 2010 12:16:10 +0100
From: Edgar Klerks <[email protected]>
Subject: [Haskell-beginners] Brainfuck interpreter stack overflow
To: [email protected]
Message-ID: <1264072570.30014.0.ca...@edgar-desktop>
Content-Type: text/plain; charset="UTF-8"
Hi Stephen,
It parses the source fine, but with complicated programs with lots of loops
-like calculating fibonacci- it fails after a while with a stack overflow.
However it does produce correct output until that point.
I am running it under ghci now, maybe I should try to compile it.
I didn't know, I used an old version of parsec.
I am using this one:
http://hackage.haskell.org/packages/archive/parsec/3.0.0/doc/html/Text-Parsec.html
Is that version ok?
Thanks for your help,
Edgar
------------------------------
Message: 2
Date: Thu, 21 Jan 2010 11:21:02 +0000
From: Stephen Tetley <[email protected]>
Subject: Re: [Haskell-beginners] Brainfuck interpreter stack overflow
To: Edgar Klerks <[email protected]>
Cc: [email protected]
Message-ID:
<[email protected]>
Content-Type: text/plain; charset=ISO-8859-1
2010/1/21 Edgar Klerks <[email protected]>:
> I am using this one:
> http://hackage.haskell.org/packages/archive/parsec/3.0.0/doc/html/Text-Parsec.html
> Is that version ok?
Ah ha - that's the later than the one I use. The authors must have
decided to change its place in the modules hierarchy.
In your case, you have already IO as part of the monad stack so you
can write debug output to the console. This might produce a lot of
output before a stack overflow though.
A minor nit-pick - language pragmas generally go at the top of the
file. It might even be that they _should_ go at the top of the file, I
had to move it to make it run for me.
Best wishes
Stephen
------------------------------
Message: 3
Date: Thu, 21 Jan 2010 13:06:54 +0100
From: Daniel Fischer <[email protected]>
Subject: Re: [Haskell-beginners] Brainfuck interpreter stack overflow
To: [email protected]
Cc: Edgar Klerks <[email protected]>
Message-ID: <[email protected]>
Content-Type: text/plain; charset="utf-8"
Am Mittwoch 20 Januar 2010 16:45:41 schrieb Edgar Klerks:
> Hello,
>
> I just started using haskell and found it many uses for it (mainly for
> scripting purposes at the moment). Now, I have written a brainfuck
> parser and interpreter in haskell, but it produces a stack overflow if
> the program runs too long and I don't understand why. I thought I made
> the interpreter loop tail recursive, which I understood is the most
> common cause of a stack overflow. Can someone help my find my fault? I
> somehow miss something. I added the program as attachment.
>
> Thanks for your help.
>
> With kind regards,
>
> Edgar Klerks
A quick look revealed that you use Control.Monad.State, which defaults to
Control.Monad.State.Lazy. That is very often too lazy for longer
calculations and produces a stack overflow.
Maybe changing the import to Control.Monad.State.Strict helps (that isn't
entirely strict either, but often reduces the opportunities for building
large thunks sufficiently).
------------------------------
Message: 4
Date: Thu, 21 Jan 2010 14:33:31 +0100
From: Edgar Klerks <[email protected]>
Subject: Re: [Haskell-beginners] Brainfuck interpreter stack overflow
To: Daniel Fischer <[email protected]>
Cc: [email protected]
Message-ID:
<[email protected]>
Content-Type: text/plain; charset="iso-8859-1"
He Daniel,
Cool, I just found out the same with the profiler. I have removed the state
entirely (it is not really neccesary) and it results in a speedup of 10x.
Storing the instructions in an array instead of an list speeded also things
up.
But I will test the original with State.Strict and see how it will perform.
Thanks,
Edgar
2010/1/21 Daniel Fischer <[email protected]>
> Am Mittwoch 20 Januar 2010 16:45:41 schrieb Edgar Klerks:
> > Hello,
> >
> > I just started using haskell and found it many uses for it (mainly for
> > scripting purposes at the moment). Now, I have written a brainfuck
> > parser and interpreter in haskell, but it produces a stack overflow if
> > the program runs too long and I don't understand why. I thought I made
> > the interpreter loop tail recursive, which I understood is the most
> > common cause of a stack overflow. Can someone help my find my fault? I
> > somehow miss something. I added the program as attachment.
> >
> > Thanks for your help.
> >
> > With kind regards,
> >
> > Edgar Klerks
>
> A quick look revealed that you use Control.Monad.State, which defaults to
> Control.Monad.State.Lazy. That is very often too lazy for longer
> calculations and produces a stack overflow.
> Maybe changing the import to Control.Monad.State.Strict helps (that isn't
> entirely strict either, but often reduces the opportunities for building
> large thunks sufficiently).
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
http://www.haskell.org/pipermail/beginners/attachments/20100121/c55c9688/attachment-0001.html
------------------------------
Message: 5
Date: Thu, 21 Jan 2010 14:49:53 +0100
From: David Virebayre <[email protected]>
Subject: Re: [Haskell-beginners] Re: testing and the culture of
Haskell
To: "Stephen Blackheath [to Haskell-Beginners]"
<[email protected]>
Cc: [email protected]
Message-ID:
<[email protected]>
Content-Type: text/plain; charset=UTF-8
On Thu, Jan 21, 2010 at 11:20 AM, Stephen Blackheath [to
Haskell-Beginners] <[email protected]>
wrote:
> All Haskell functions are pure without exception. Â For example:
> greet :: String -> IO ()
> greet name = putStrLn $ "Hello, "++name
> This is a pure function from String to IO (). Â This function (like all
> Haskell functions) has no side effects. Â Its return value of type IO ()
> merely _represents_ an IO action. Â The runtime system knows how to act
> on this representation.
> This also means that there is no such thing in Haskell as marking a
> function as side-effecting.
> This distinction may be subtle, but it's important.
Coming from an imperative background, I have found that distinction to
be confusing.
I like to understand how things work. For example, haskell's lazyness
confused me a lot until I heard about thunks.
Back to IO. What exactly would be the representation of an IO action,
if not an abstract notion ? Hopefully that is optimised out by the
compiler. Indeed, If I look at the compiled output of a simple
program, it looks to me like the effects are executed within the
function, and no special structure is returned.
David.
------------------------------
Message: 6
Date: Thu, 21 Jan 2010 14:02:11 +0000 (UTC)
From: Zbigniew Stanasiuk <[email protected]>
Subject: [Haskell-beginners] Function nesting
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=us-ascii
Hi all,
I've just started learning Haskell and I have no idea how to nest function in
following structure:
Mod(5*Mod(4*Mod(3*Mod(2*Mod(1, m), m), m), m), m) ... etc.
Could someone help me.
Regards,
Zbig
------------------------------
Message: 7
Date: Thu, 21 Jan 2010 14:44:57 +0000
From: Magnus Therning <[email protected]>
Subject: Re: [Haskell-beginners] Function nesting
To: Zbigniew Stanasiuk <[email protected]>
Cc: [email protected]
Message-ID:
<[email protected]>
Content-Type: text/plain; charset=UTF-8
On Thu, Jan 21, 2010 at 2:02 PM, Zbigniew Stanasiuk
<[email protected]> wrote:
> Hi all,
>
> I've just started learning Haskell and I have no idea how to nest function in
> following structure:
> Mod(5*Mod(4*Mod(3*Mod(2*Mod(1, m), m), m), m), m) ... etc.
> Could someone help me.
I don't quite understand what you mean by "nest function". 'Mod'
looks like a constructor in your code, but I somehow get the feeling
that you actually indend 'Mod' to be a function...
/M
--
Magnus Therning (OpenPGP: 0xAB4DFBA4)
magnusï¼ therningï¼org Jabber: magnusï¼ therningï¼org
http://therning.org/magnus identi.ca|twitter: magthe
------------------------------
Message: 8
Date: Thu, 21 Jan 2010 14:54:33 +0000 (UTC)
From: Zbigniew Stanasiuk <[email protected]>
Subject: [Haskell-beginners] Re: Function nesting
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=us-ascii
Zbigniew Stanasiuk <zbigergofun <at> gmail.com> writes:
>
> Hi all,
>
> I've just started learning Haskell and I have no idea how to nest function
in
> following structure:
> Mod(5*Mod(4*Mod(3*Mod(2*Mod(1, m), m), m), m), m) ... etc.
> Could someone help me.
>
> Regards,
> Zbig
>
>
To be precise, I have list [1.20]::Int, mod function, m::Int as a input and as
a result I want to get above. I have tried to play with fold family functions
but no good results.
Zbig
------------------------------
Message: 9
Date: Thu, 21 Jan 2010 15:55:39 +0100
From: Daniel Fischer <[email protected]>
Subject: Re: [Haskell-beginners] Function nesting
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset="iso-8859-1"
Am Donnerstag 21 Januar 2010 15:02:11 schrieb Zbigniew Stanasiuk:
> Hi all,
>
> I've just started learning Haskell and I have no idea how to nest
> function in following structure:
> Mod(5*Mod(4*Mod(3*Mod(2*Mod(1, m), m), m), m), m) ... etc.
> Could someone help me.
Instead of func(a,b), write func a b. Arguments which are compund
expressions themselves must be parenthesized, so
mod (5*mod (4*mod (3*mod (2*mod 1 m) m) m) m) m
But that is completely unreadable.
foldl' (\z x -> (x*z) `mod` m) 1 [1 .. 5]
Much better :)
>
> Regards,
> Zbig
>
------------------------------
Message: 10
Date: Thu, 21 Jan 2010 16:06:37 +0100
From: Daniel Fischer <[email protected]>
Subject: Re: [Haskell-beginners] Re: Function nesting
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset="iso-8859-1"
Am Donnerstag 21 Januar 2010 15:54:33 schrieb Zbigniew Stanasiuk:
> I have tried to play with fold family functions
> but no good results.
Nice coincidence :)
------------------------------
_______________________________________________
Beginners mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/beginners
End of Beginners Digest, Vol 19, Issue 18
*****************************************