Re: [Haskell-cafe] Minim interpreter

2007-07-23 Thread Chaddaï Fouché
I wrote such an interpreter though the code is quite ugly due to my lack of experience in the field as well as with Haskell... It took me the better part of two hour but mainly because I didn't use Parsec before this. I would of course be happy of any suggestion to amend it but a plain rewriting

Re: [Haskell-cafe] Minim interpreter

2007-07-23 Thread Chaddaï Fouché
There was more than some bugs, and a lack of strictness that led to a stack overflow for high values of x... So here is a better version (not quite there still, but better). -- Jedaï {-# OPTIONS -fbang-patterns -funbox-strict-fields #-} module Minim (Statement (..), Test (..), Program (..), Expr

Re: [Haskell-cafe] Minim interpreter

2007-07-22 Thread Jon Harrop
On Saturday 21 July 2007 01:41:58 Hugh Perkins wrote: Ok, that got the variables working. ... Don't fizzle out on me now: this was just getting interesting! :-) -- Dr Jon D Harrop, Flying Frog Consultancy Ltd. OCaml for Scientists http://www.ffconsultancy.com/products/ocaml_for_scientists/?e

Re: [Haskell-cafe] Minim interpreter

2007-07-22 Thread Hugh Perkins
heh! well everyone was busy working on icfp or something, so the newsgroup was pretty dead :-) And I played with opengl a little, which gave better results than I thought, but not good enough to pursue, and the whole program was in imperative dos anyway, so I couldnt quite see what was the point

[Haskell-cafe] Minim interpreter

2007-07-20 Thread Jon Harrop
Anyone care to code up a Haskell implementation of this trivial interpreter for comparison: http://groups.google.co.uk/group/comp.lang.lisp/browse_frm/thread/7b1ab36f5d5cce0a/0ca59e0bfb794e07?hl=en#0ca59e0bfb794e07 -- Dr Jon D Harrop, Flying Frog Consultancy Ltd. OCaml for Scientists

Re: [Haskell-cafe] Minim interpreter

2007-07-20 Thread Hugh Perkins
Newbie question: why does the following give Not in scope 'c' for the last line? string :: Parsec.Parser String string = do c - Parsec.letter do cs - string return c:cs Parsec.| return [c] (This is copied more or less rote from

Re: [Haskell-cafe] Minim interpreter

2007-07-20 Thread Brandon Michael Moore
On Fri, Jul 20, 2007 at 10:10:58PM +0200, Hugh Perkins wrote: Newbie question: why does the following give Not in scope 'c' for the last line? I assume you meant string :: Parsec.Parser String string = do c - Parsec.letter do cs - string return c:cs

Re: [Haskell-cafe] Minim interpreter

2007-07-20 Thread Hugh Perkins
Kindof vaguely made a start on this, but cant quite see how to handle variables. I guess variables can be stored as a (Map.Map String Double), at least for a first draft? Then, I'm building up two hierarchies in parallel: - a set of parsec functions to parse the incoming string into a Program

Re: [Haskell-cafe] Minim interpreter

2007-07-20 Thread Mark Wassell
Hugh Perkins wrote: That works just fine as long as the only thing eval has to cope with is print statements (so eval has type IO ()), but I'm guessing the clean solution is to thread a Map.Map through that somehow? You could do that but your code starts to become messy and you'll hit other

Re: [Haskell-cafe] Minim interpreter

2007-07-20 Thread Hugh Perkins
Ok, that got the variables working. Example: *Minim evaluateprog $ ProgramTree ( ProgramLeaf $ AssignmentStatement( VarAssignment (Variable test) ( ValueFromConstant (Constant 3 ( PrintStatement (PrintValue( ValueFromVariable(Variable test 3.0 3.0 I'm having eval return the IO monad,