[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Re: [QUIZ] Bytecode Compiler (#100

Ross Bamford

11/9/2006 10:42:00 AM

On Wed, 2006-11-08 at 08:47 +0900, Justin Bailey wrote:
> Some people started doing the Ruby quiz problems using Haskell, and
> this was a perfect opportunity for me to learn some Haskell. So here's
> my solution below, in Haskell. It's hard to test the byte code
> interpretation but all the expression do evaluate to the correct
> values.
>
> If anyone has questions about the Haskell code, please let me know.
> I'm just learning it and its really cool!
>

Aww man, now I'm gonna have to look into Haskell a bit more :) I've been
putting it off for a while, but this is too cool to not have a play
with!

Because I'm currently Haskell-ignorant, however, I don't know how to run
your solution :( . What interpreter (or compiler?) should be used? I
have Hugs installed, but that complains about a "Syntax error in input
(unexpected backslash (lambda))" at line 1.

--
Ross Bamford - rosco@roscopeco.REMOVE.co.uk


4 Answers

Louis J Scoras

11/9/2006 12:01:00 PM

0

On 11/9/06, Ross Bamford <rossrt@roscopeco.co.uk> wrote:
>
> Aww man, now I'm gonna have to look into Haskell a bit more :) I've been
> putting it off for a while, but this is too cool to not have a play
> with!

You won't be disappointed. Haskell is an amazingly cool language.

> Because I'm currently Haskell-ignorant, however, I don't know how to run
> your solution :( . What interpreter (or compiler?) should be used? I
> have Hugs installed, but that complains about a "Syntax error in input
> (unexpected backslash (lambda))" at line 1.

It looks like its supposed to be embedded in LaTeX. Just remove the
first and last lines since the TeX directives look like lambdas to
Haskell.

\x -> x * x
<==>
lamba {|x| x*x}

Also, Haskell is very picky about formatting. Your going to get a
bunch of errors because of line wraps.


--
Lou.

Ross Bamford

11/9/2006 3:00:00 PM

0

On Thu, 09 Nov 2006 12:00:38 -0000, Louis J Scoras =

<louis.j.scoras@gmail.com> wrote:

> On 11/9/06, Ross Bamford <rossrt@roscopeco.co.uk> wrote:
>>
>> Aww man, now I'm gonna have to look into Haskell a bit more :) I've b=
een
>> putting it off for a while, but this is too cool to not have a play
>> with!
>
> You won't be disappointed. Haskell is an amazingly cool language.
>

It certainly looks it, too. I've glanced a few times, and put it on my =

list of things to do, but now I've got a reason to bump it up the list a=
=

bit :)

>> Because I'm currently Haskell-ignorant, however, I don't know how to =
run
>> your solution :( . What interpreter (or compiler?) should be used? I
>> have Hugs installed, but that complains about a "Syntax error in inpu=
t
>> (unexpected backslash (lambda))" at line 1.
>
> It looks like its supposed to be embedded in LaTeX. Just remove the
> first and last lines since the TeX directives look like lambdas to
> Haskell.
>

Ahh, gotcha. I did wonder, but being totally Haskell-ignorant I didn't =

want to just start deleting stuff :)

> \x -> x * x
> <=3D=3D>
> lamba {|x| x*x}
>
> Also, Haskell is very picky about formatting. Your going to get a
> bunch of errors because of line wraps.
>

Yeah, I think I'm finding that now. Never mind, at least I'll get the =

chance to play with Haskell a bit today as I try to get it going :)

Cheers,
-- =

Ross Bamford - rosco@roscopeco.remove.co.uk

jgbailey

11/9/2006 6:59:00 PM

0

On 11/9/06, Ross Bamford <rossrt@roscopeco.co.uk> wrote:
> Aww man, now I'm gonna have to look into Haskell a bit more :) I've been
> putting it off for a while, but this is too cool to not have a play
> with!

Awesome!

>
> Because I'm currently Haskell-ignorant, however, I don't know how to run
> your solution :( . What interpreter (or compiler?) should be used? I
> have Hugs installed, but that complains about a "Syntax error in input
> (unexpected backslash (lambda))" at line 1.

Like someone else pointed out, it's meant to be in a LateX document.
It's called "literate coding" and Haskell is the first place I
encountered it. The basic idea is you flip the normal source/comments
order and make comments the number 1 element in the document. Code is
then embedded in \begin{code} & \end{code} directives. (throwaway
comment: enabling ruby to run "literate code" would make a cool quiz).

Anyways, to run a literate haskell file in hugs, just save it with a
"lhs" extension. At least, that works for me in WinHugs.

To get a properly formatted version, its available on the web at:

http://www.haskell.org/haskellwiki/Haskell_Quiz/Bytecode_Compiler/Solution_Jus...

That version actually works (I'll be resubmitting in a minute). To run
all the tests there, type "interpret_tests" after you load the file.

Justin

p.s. One nice thing about literate haskell is you can copy that entire
page (i.e. don't worry about trying to grab only the code), paste it
into an lhs file, and run it. Works great on blogs too!

James Gray

11/9/2006 8:16:00 PM

0

On Nov 9, 2006, at 12:58 PM, Justin Bailey wrote:

> (throwaway comment: enabling ruby to run "literate code" would make
> a cool quiz).

Great, write it up for us so we can all learn how it works!

suggestion@rubyquiz.com

James Edward Gray II