[Haskell-cafe] Case-insensitive lexing with Alex

2008-01-28 Thread Joel Reymont

Any suggestions on how to implement case-insensitive lexing with Alex?

Thanks, Joel

--
http://wagerlabs.com





___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Re: Case-insensitive lexing with Alex

2008-01-28 Thread Joel Reymont


On Jan 28, 2008, at 2:44 PM, Geoffrey Mainland wrote:

map toLower onto your input before you pass it to your lexer? Or do  
you

only want keywords to be case-insensitive?



Just keywords. You can have Array or array or aRrAy.

--
http://wagerlabs.com





___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] C# parser written in Haskell

2008-01-27 Thread Joel Reymont

Does anyone have a C# parser written in Haskell?

Thanks, Joel

--
http://wagerlabs.com





___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Yampa / AFRPVectorSpace.hs

2007-12-17 Thread Joel Reymont

On Dec 17, 2007, at 4:30 PM, Peter Verswyvelen wrote:


Maybe you could place Yampa in a Darcs depot?



darcs get http://wagerlabs.com/yampa

I think we should move it to Google Code, though.

--
http://wagerlabs.com





___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Expert systems

2007-12-04 Thread Joel Reymont

Is there an expert system implemented in Haskell, or a library perhaps?

A CLIPS/RETE implementation?

The main stumbling point, from my perspective, is how to implement a  
knowledge base and check whether patterns with a certain shape have  
been asserted. It's much easier to do this in a dynamically-typed  
language.


Am I mistaken?

Thanks, Joel

--
http://wagerlabs.com





___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Missing _environ

2007-11-09 Thread Joel Reymont

Dan,

On Nov 9, 2007, at 12:58 AM, Dan Piponi wrote:


Well that was the crucial fact I needed. 6.8.1 is now built. ghci
doesn't work, it complains about an unknown symbol '_environ' in
HSbase-3.0.0.0.o



The installation process strips the binaries which strips away _environ.

You need to either find the place where install-sh -s is invoked and  
remove -s or copy ghc from compiler/stage2 into your installation  
directory. I think this should work.


Thanks, Joel

--
http://wagerlabs.com





___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Re: Composing trading strategies (was: Should I step into a minefield? / Writing a trading studio in Haskell)

2007-11-08 Thread Joel Reymont

Greg,

Can you post a couple of examples of what the trading strategies look  
like?


Thanks, Joel

On Nov 8, 2007, at 7:32 PM, Greg Fitzgerald wrote:

The idea is that the user composes an 'openPosition' and  
'closePosition'
trading strategies from a combinator library and gives them to the  
trading
platform.  The user's trading strategies are nothing more than a  
numeric

parser combinators.


--
http://wagerlabs.com





___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] HOC is dead! Long live HOC!

2007-11-07 Thread Joel Reymont
BridgeSupport [1] is new functionality in Leopard that makes the  
current Haskell Objective-C bindings (HOC) obsolete (almost).


---
The metadata is intended to be a resource for use beyond bridging.  
Most frameworks on the system provide two chunks of XML BridgeSupport  
metadata; succinct and full.


The succinct version contains all of the metadata not provided by the  
Objective-C runtime (which provides about 80% of what is necessary to  
do full fidelity calls in / out of Objective-C via libffi).


The full version contains just that, the full metadata required to  
describe the APIs of the framework, including all the bits that could  
be gleaned at runtime.

---

BridgeSupport makes it unnecessary to parse Cocoa headers since all  
the required data is right there in plain XML [2]. It's no longer  
necessary to bundle libffi with HOC either since Leopard comes with a  
much improved version.


I hereby propose to close up the old HOC project on SourceForge and  
set up a new one at GoogleCode. I already did this but GoogleCode  
noticed the SF project and is now waiting for permission from Wolfgang  
and Andre.


Thanks, Joel

[1] http://www.friday.com/bbum/2007/10/27/pyobjc-20-pyobjc-in-leopard/
[2] /System/Library/Frameworks/AppKit.framework/Resources/ 
BridgeSupport/AppKitFull.bridgesupport


--
http://wagerlabs.com





___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Memory-mapped arrays?

2007-11-07 Thread Joel Reymont

Is there such a thing as memory-mapped arrays in GHC?

I'm looking for something that would let me memory-map a file of  
floats and access it as an array.


Thanks, Joel

--
http://wagerlabs.com





___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Should I step into a minefield? / Writing a trading studio in Haskell

2007-11-07 Thread Joel Reymont
I need to pick among the usual list of suspects for a commercial  
product that I'm writing. The suspects are OCaml, Haskell and Lisp and  
the product is a trading studio. My idea is to write something like  
TradeStation [1] or NinjaTrader, only for the Mac.


It would be quite nifty to use SPJ's financial combinator approach  
and, for example, embed Yi (Haskell editor).


One of the key features of the product would be the ability to model  
your trading logic using a trading DSL. I'm thinking that this DSL  
could well be Haskell but I'm concerned about stepping into a minefield.


I will need to embed GHC into the app, for example, and I understand  
that the GHC API does not offer unloading of code at the moment. I  
would prefer not to bundle GHC separately so I don't think the hs- 
plugins approach would work for me. Maybe I'm mistaken.


Most of all, I'm concerned that my users will need to face the error  
reports from GHC and could get tripped by laziness, i.e. write  
something that would make the app run out of memory. Off the top of my  
head I can't figure out a way to limit what my users can do without  
analyzing the Haskell AST within the GHC API and complaining if  
necessary.


Can someone with experience in offering a Haskell DSL to their users  
please comment?


Notice that I'm not even mentioning being concerned with the  
unpredictable effects of laziness. There's probably a reason why Jane  
St Capital is using OCaml instead of Haskell. I'm not going to play in  
that league but my knee-jerk reaction is to use OCaml or Lisp and  
avoid laziness altogether. I just can't see how laziness can help in  
processing real-time price data.


Thanks, Joel

[1] http://www.tradestation.com/default_2.shtm
[2] http://www.ninjatrader.com/webnew/index.htm

--
http://wagerlabs.com





___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Re: HOC is dead! Long live HOC!

2007-11-07 Thread Joel Reymont


On Nov 7, 2007, at 9:57 PM, Wolfgang Thaller wrote:

One big piece of information we need that is currently missing from  
the BridgeSupport files is which declaration comes form which header  
file. HOC's module structure currently follows Apple's .h files, and  
we need the module system for resolving naming ambiguities.


Why not assume that each class goes into a file of its own and all  
classes in a directory matching the name of the framework? You will  
then have AppKit/NSWindow.hs, etc. I think this is how it's done right  
now. Constants and such can be gathered in AppKit/AppKit.hs.


I haven't had a chance recently to do a thorough comparison of  
different open source hosting providers, so I have no opinion on  
this one. So if you want to invest time in maintaining HOC, and you  
want to maintain it on GoogleCode, then so be it. How do I give my  
permission?



Either you or Andre should have received an email from Google Code.  
Please add wagerlabs to the project admins on SourceForge and I'll  
look into it.


Thanks, Joel

--
http://wagerlabs.com





___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] CPP, Leopard and Haskell Objective-C bindings

2007-11-06 Thread Joel Reymont
It seems that the current approach taken by HOC is to strip  
preprocessing directives. This may not have been a problem before  
Leopard but Cocoa header files are now full of macros in most unusual  
places, e.g.


@interface NSObject (NSDeprecatedMethods)

+ (void)poseAsClass:(Class)aClass  
DEPRECATED_IN_MAC_OS_X_VERSION_10_5_AND_LATER;


@end

I'm trying to figure out the easiest way to run CPP over the header  
files before processing them in HOC.


Is there a CPP written in Haskell and packaged as a library?

Does someone have a quick Haskell solution for running CPP over a  
header file (with include paths?), redirecting into a temp file and  
reading that back into Haskell?


Should I preprocess all Cocoa header files using make and then read  
these in?


Thanks, Joel

--
http://wagerlabs.com





___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Re: CPP, Leopard and Haskell Objective-C bindings

2007-11-06 Thread Joel Reymont


On Nov 6, 2007, at 6:57 PM, Wolfgang Thaller wrote:

That is not exactly what we want, I think. Currently, HOC parses  
things file-by-file, so we do NOT want to follow #include  
directives. We might just process the line pragmas from CPP to keep  
track of where things came from, OTOH.


You _do_ need to pre-process. Witness the following:

@interface NSWindow : NSResponder
#if MAC_OS_X_VERSION_MAX_ALLOWED = MAC_OS_X_VERSION_10_5
NSAnimatablePropertyContainer, NSUserInterfaceValidations
#else
NSUserInterfaceValidations
#endif
{
/*All instance variables are private*/
...

It breaks the HOC parser.

I'm still working on cleaning up my InterfaceGenerator rewrite (I  
didn't have enough time to finihs last weekend, so maybe next  
weekend, but at least I'm motivated now).


I'll be waiting anxiously.

I think any more more elaborate improvements to the interface  
generator should be based on that instead of my old code.



Maybe I can merge my changes when you are ready. What are your  
improvements to the interface generator?


Thanks, Joel

--
http://wagerlabs.com





___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Leopard: ghc 6.8.1 and the case of the missing _environ

2007-11-06 Thread Joel Reymont

Symptoms:

You build 6.8.1 from source on Leopard (x86 in my case) and then

junior:ghc-6.8.1 joelr$ ghci
GHCi, version 6.8.1: http://www.haskell.org/ghc/  :? for help
ghc-6.8.1:
/usr/local/lib/ghc-6.8.1/lib/base-3.0.0.0/HSbase-3.0.0.0.o: unknown  
symbol `_environ'
Loading package base ... linking ... ghc-6.8.1: unable to load package  
`base'


Problem:

ghc binaries are being stripped upon installation which eliminates  
_environ, e.g.


junior:tmp joelr$ nm x|grep environ
2ff0 T ___hscore_environ
0004d004 D _environ

junior:tmp joelr$ strip x
junior:tmp joelr$ nm x|grep environ

Solution:

Need to make sure install-sh does _not_ use the -s option. Haven't  
found out where this needs to be done yet. A temporary workaround is  
to ask Manuel for the pre-built binaries.


Thanks, Joel

--
http://wagerlabs.com





___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Embedding the GHC API

2007-10-31 Thread Joel Reymont

Has anyone tried to embed GHC as a library recently?

What is the size of the resulting binary?

I'm assuming a bare minimum of needed libraries.

Thanks, Joel

--
http://wagerlabs.com





___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Quasiquotations part of GHC?

2007-10-29 Thread Joel Reymont

Folks,

Did quasiquotations ever make it into the GHC tree?

They were implemented as a patch to 6.7.

Thanks, Joel

--
http://wagerlabs.com





___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Erlang VM in Haskell

2007-08-16 Thread Joel Reymont


On Aug 16, 2007, at 1:36 PM, Neil Bartlett wrote:


However, wouldn't it be rather difficult, given that there doesn't
seem to be a publicly available specification for the Erlang VM or the
BEAM file format


Very difficult, correct. I use Erlang daily, in fact Erlang is what  
brings bread to my table. I want to learn more about the Erlang  
insides so I'll simply dig in.



Perhaps it would be interesting to look at a slightly more constrained
problem: can Erlang's message passing model (including distributed
messaging across a network) and process monitoring facilities be
replicated in Haskell?


My ultimate goal is to have a version of the Erlang VM that's  
suitable for running trading systems, i.e. one that allows high-speed  
numerics. I don't have much interest in replicating OTP in Haskell  
and Haskell may ultimately not be the right choice for what I envision.


Thanks, Joel

--
http://wagerlabs.com





___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Erlang VM in Haskell

2007-08-15 Thread Joel Reymont

Folks,

I would like to write an Erlang VM in Haskell. I first thought of  
OCaml but Haskell has SMP and lazy evaluation may come in handy.  
Plus, I'll need help in this project like in no other and support  
from the Haskell community has always been outstanding.


I'm doing this to learn more about the Erlang internals and to  
acquire some skills in the process. I'm also hoping to be at least as  
fast as the existing Erlang VM (written in C) and to be able to  
extend the VM in a functional language.


With C you can implement a threaded VM using GCC labels or switch- 
style [1]. What is the most efficient approach in Haskell?


I'm thinking using CPS and building up a chain of closures. Would  
this work well? Any other suggestions?


The Haskell repo for the initial HEM (Haskell Erlang Machine) is at  
http://darcs.haskell.org/hem. A much improved HAW implementation will  
follow in the not so near future.


Thanks, Joel

[1] http://www.complang.tuwien.ac.at/forth/threaded-code.html

--
http://wagerlabs.com





___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Picking an architecture for a Haskell web app

2007-05-10 Thread Joel Reymont


On May 10, 2007, at 10:01 AM, Bayley, Alistair wrote:


Depends. Did you leave out WASH intentionally?
  http://www.informatik.uni-freiburg.de/~thiemann/WASH/


Nope, I forgot about it but looked at the Hemp app this morning.

Thanks, Joel

--
http://wagerlabs.com/





___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Debugging

2007-05-10 Thread Joel Reymont


On May 10, 2007, at 10:19 AM, Jules Bean wrote:

The 'next step' is to move from testing by hand in ghci to writing  
quickcheck properties / smallcheck / unit tests for the functions.


I still don't understand the difference between QC and SC. Would  
someone kindly explain and provide an example or two of when SC  
should be used?


Thanks, Joel

--
http://wagerlabs.com/





___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Telling Cabal not to install the executable

2007-05-10 Thread Joel Reymont

I tell Cabal to build library and a test harness.

How can I tell Cabal that I only want the library installed?

Thanks, Joel

--
http://wagerlabs.com/





___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Picking an architecture for a Haskell web app

2007-05-09 Thread Joel Reymont

Folks,

I have finished an alpha version of my EasyLanguage [1] to C#  
compiler and need to deploy it on Amazon EC2/S3.


The compiler web interface is very simple: paste EL code, get back C#  
code or the same EL code with the error highlighted. I view the site  
as more than just a compiler, though, and want a blog, forums, etc.  
Last but not least, I want to be able to update portions of the site  
without shutting it down.


My choice seems to boil down to HAppS [2], HOPE [3], or a combination  
of Ruby/Rails with Lambdabot.


At first glance, HAppS lacks publishing (my ultimate need) but  
promises an interface to S3 sometime in the future. My understanding  
is that it's ready but is not being released. HAppS is heavy on  
features that I may not make use of. I had a hard time understanding  
the HPaste [4] code written using HAppS and I don't fancy using XSLT  
as my HTML template language.


HOPE has a publishing framework (blog, RSS, comments). I could write  
the forums or just use Google Groups. I like the module system and  
the FCGI interface should let me couple HOPE with Lighty [5]. The  
HOPE code base looks clean and simple and I'm guessing that adding  
Lambdabot-style dynamic loading of modules would be straightforward.  
Overall, HOPE has everything that I need, without unnecessary extras.  
It does not have an interface to Amazon S3, though, and I would need  
that to rewrite the storage bits to use S3 instead of a regular  
database.


Lambdabot by itself doesn't offer much apart from robust dynamic  
loading of Haskell code. Its features have been heavily tested,  
though, which gives me a warm feeling. I'm thinking that the same hot- 
loading technology that Lambdabot uses could be coupled with either  
HAppS or HOPE. Lambdabot has a FCGI which should make mixing it with  
HOPE particularly easy.


Going with Ruby and Rails I will have everything I need and more. The  
compiler could run in a separate server (think Lambdabot) but I would  
need to manage two different platforms.


Is my assessment correct? Did I miss anything?

What approach do you favor?

Thanks, Joel

P.S. I have the same compiler written in OCaml which is what I  
started with. Developing it has been a relative breeze but deploying  
on the web was a tale of frustration. I gave up and finished the  
Haskell version.


[1] http://lambda-the-ultimate.org/node/2201
[2] http://happs.org/HAppS/README.html
[3] http://hope.bringert.net/about
[4] http://hpaste.org
[5] http://www.lighttpd.net/

--
http://wagerlabs.com/



___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Indenting with PPrint

2007-05-08 Thread Joel Reymont

Brandon,

On May 8, 2007, at 12:33 AM, Brandon Michael Moore wrote:


braces x = group (PP. braces (nest 4 (linebreak  x)  linesbreak)


I ended up with the following:

nest = PP.nest 4
braces x = nest (lbrace $ x) $ rbrace

If you happen to be formatting C I've also worked out how to get  
nice argument

lists out of both pretty printers.


I'm formatting C# but I'll certainly take your arg list tips.

Thanks, Joel

--
http://wagerlabs.com/





___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Co-arbitrary

2007-05-08 Thread Joel Reymont
Would someone kindly explain why we need co-arbitrary in QuickCheck  
and how to define it?


Detailed examples would be awesome!

I would be willing to paste an in-depth explanation on my wall and  
keep it forever.


Thanks in advance, Joel

--
http://wagerlabs.com/





___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] QuickCheck invariants for AST transformations

2007-05-08 Thread Joel Reymont
I'm looking for suggestions on how to create invariants for the  
following AST transformation code. Any suggestions are appreciated!


I asked this question before and Lennart suggested abstract  
interpretation as a solution. This would require interpreters for  
both ASTs to determine that the result they achieve is the same. I  
don't fancy writing a C# interpreter, though, so I'm looking for an  
easier way out.


Thanks, Joel

[1] http://tinyurl.com/368whq

---

instance SharpTransform C.Type Type where
toSharp C.TyInt = return TyInt
toSharp C.TyFloat = return TyFloat
toSharp C.TyStr = return TyStr
toSharp C.TyBool = return TyBool
toSharp (C.TyArray x) = liftM2 TyArray (toSharp x) (return [])
toSharp (C.TySeries C.TyFloat) = return $ TyCustom DataSeries
toSharp (C.TySeries x) = error $ Unsupported series type:  ++  
show x

toSharp (C.TyProp x) = toSharp x
toSharp C.TyUnit = return TyVoid

instance SharpTransform C.VarIdent VarIdent where
toSharp (C.VarIdent x) = return $ VarIdent x

instance SharpTransform (Maybe C.Expr) (Maybe Expr) where
toSharp Nothing = return Nothing
toSharp (Just e) = liftM Just (toSharp e)

instance SharpTransform C.Subscript [Expr] where
toSharp xs = mapM toSharp xs

instance SharpTransform C.BarsAgo Expr where
toSharp C.Now = return $ Int 0
toSharp (C.BarsAgo e) = toSharp e


--
http://wagerlabs.com/





___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Indenting with PPrint

2007-05-07 Thread Joel Reymont

Folks,

Are you using UU.PPrint [1]? Can you tell me how to print stuff like  
this?


{
 blah
 blah
}

I tried the following which sort of works but doesn't return the  
closing brace to the indentation level of the first one.


braces x = PP.braces $ linebreak  indent 4 x

Thanks, Joel

[1] http://tinyurl.com/25t6xz

--
http://wagerlabs.com/





___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Re: [Haskell] Newbie: what are the advantages of Haskell?

2007-04-26 Thread Joel Reymont
The biggest advantage of Haskell to me is that it helps me write  
better programs in other languages.


For one reason or another Haskell never turns out to be my final  
implementation language my my programs gain in the process.


Joel

--
http://wagerlabs.com/





___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Is Template Haskell a suitable macro language?

2007-04-24 Thread Joel Reymont
I'm finding myself dealing with several large abstract syntax trees  
that are very similar in nature. The constructor names would be the  
same or one type may be a small extension of another.


This is something that I wouldn't worry about with Lisp, for example,  
as I would create a bunch of macros for creating syntax trees and  
reuse them all over. I cannot do this in Haskell, though, as my  
macros are functions and so I must repeat them for every AST since  
they return different types.


I'm wondering if Template Haskell is a suitable replacement for Lisp  
macros.


What is the consensus?

Thanks, Joel

--
http://wagerlabs.com/





___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Creating QuickCheck properties

2007-04-23 Thread Joel Reymont

Folks,

I have code like this that I want to test with QuickCheck but I'm  
having trouble imagining how I would wrap it up in a property.


Do I make sure that id, subs, back are always morphed properly or do  
I leave that to separate properties for their respective types?


Do I then ensure that array types are always unwrapped (see getType  
below), that a series variable is always declared, code added and a  
series reference returned?


Last but not least, is monadic testing part of Test.QuickCheck.*?

Thanks, Joel

type Core a = State CoreUnit a

data CoreUnit
= Core
  { coreSym :: Integer -- starting # for gensym
  , coreVars :: M.Map String VarDecl
  , coreCode :: M.Map Integer [Statement]
  }
deriving (Show, Eq)

morphHistArrayAccess :: VarIdent - Subscript - BackRef - C.Core  
C.Expr

morphHistArrayAccess id subs back = do
  id' - morph id
  subs' - morph subs
  back' - morph back
  (C.TyArray ty) - getType id'
  s - genSym series
  addVar s (C.TySeries ty) [] Nothing
  addCodeFront 1 [ C.AddToSeries (C.VarIdent s) (C.Var id' subs') ]
  return $ C.Series (C.VarIdent s) back'


--
http://wagerlabs.com/





___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] QuickCheck testing of AST transformers

2007-04-23 Thread Joel Reymont
My previous post did not receive any replies so I thought I might try  
generalizing the problem a bit...


Suppose I'm parsing a language into a syntax tree and then  
transforming that tree into another AST representing a core  
language. The core language is a more general AST that should help  
with compiling to other languages.


My problem is how to best structure my AST transformations to be able  
to test them with QuickCheck. I suspect that I'm not going about it  
in the most optimal way so I thought I should ask for suggestions.


The transformation into the core AST applies operations to simplify,  
or desugar, the AST of the original language. Here's sample code in  
the source language which, incidentally, was recently highlighted at  
Lambda the Ultimate [1].


Array: MyArray[10](10 + 2);
Value1 = MyArray[5][10];

This declares an array of 10 elements and initializes each element to  
12. Value1 (a built-in variable) is then initialized to the value of  
element #5 as of 10 bars ago. A bar is, basically, a stock quote. The  
code is invoked on every bar and so 5 bars ago can be treated as 5  
invocations ago.


The syntax tree of the above code is a 1-1 mapping. We declare an  
array of integers of 10 elements. Initialize it to the sum of two  
integers and then assign to Value1.


[ ArrayDecs [ VarDecl (VarIdent MyArray) TyInt [Int 10]
  (Op Plus (Int 10) (Int 2)) ]
, Assign (VarIdent Value1) [] (Var (VarIdent MyArray) [Int 5]
 (BarsBack (Int 10))) ]

The desugared version does away with the array declaration  
statement and declares MyArray to be a variable of array type. Arrays  
in the core language do not remember values from one invocation to  
another but there's a data series type, so we declare a series  
variable to hold the value of element #5.


We must manually store the value of the array element in the data  
series and can then refer to the value of the series 10 data points ago.


vars = [ (MyArray, VarDecl (TyArray TyInt) [Int 10]
   (Just (Plus (Int 10) (Int 2
   , (series0, VarDecl (TySeries TyInt) [] Nothing)
   ]

code = [ AddToSeries (VarIdent series0) (Var (VarIdent MyArray)  
[Int 5])

   , Assign (Var (VarIdent Value1) [])
(Series (VarIdent series0) (Int 10))
   ]

The next step would be to take the above core syntax tree and  
transform it yet again into a C# (or other target language) AST. It's  
assumed that all target languages have a data series type.


The OCaml version of my code translated directly into the C# AST but  
I figured an intermediate syntax tree will help me translate into  
other languages such as Haskell, Erlang or OCaml.


The part I can't figure out is how to come up with a set of  
invariants for my transformations.


Should I, for example, state that every access to an array value in a  
previous invocation should introduce an extra variable to hold the  
series plus the appropriate assignment code?


Should I write the translator as a series of small transformers in  
the ST monad that can be threaded and tested separately?


Thanks in advance, Joel

[1] http://lambda-the-ultimate.org/node/2201

--
http://wagerlabs.com/





___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Re: QuickCheck subsumes unit testing

2007-04-21 Thread Joel Reymont


On Apr 21, 2007, at 2:54 AM, Donald Bruce Stewart wrote:


Just to walk the walk, and not just talk the talk, here's a quick unit
testing 'diff' driver I hacked up for QuickCheck.


Yay! I'll be the first to switch over!


Note that we actually probably want to use SmallCheck here,


I don't have an idea of when to prefer SmallCheck over QuickCheck. An  
explanation and, possibly, a tutorial would be very welcome! Anyone?


Note also, the driver would need further extending, since we've  
changed

the structure of the Testable values.


Can you elaborate on further extending? What direction should I  
extend it in?


Thanks, Joel

--
http://wagerlabs.com/





___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Writing guards shorthand

2007-04-19 Thread Joel Reymont
Support I want to infer the type given an Op that looks like this  
(incomplete):


data Op
= Minus
| Plus
| Mul
| LT
| GT

Is there a shorthand way of bunching Minus, Plus and Mul in a  
function guard since they all result in TyNum whereas the rest in  
TyBool?


I really don't want several function clauses and neither do I want  
separate guards for every constructor.


Thanks, Joel

--
http://wagerlabs.com/





___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Writing guards shorthand

2007-04-19 Thread Joel Reymont

This is what want. Notice the succinctness.

Objective Caml version 3.10+dev24 (2007-02-16)

# type foo = A | B | C | D | E | F
  ;;
type foo = A | B | C | D | E | F

# A;;
- : foo = A

# let infer = function | A | B | C - true; | D | E | F - false;;
val infer : foo - bool = fun

# infer A;;
- : bool = true

# infer B;;
- : bool = true

# infer D;;
- : bool = false

# infer F;;
- : bool = false
#

--
http://wagerlabs.com/





___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Re: Writing guards shorthand

2007-04-19 Thread Joel Reymont


On Apr 19, 2007, at 4:10 PM, Jón Fairbairn wrote:


Is there some reason why you don't want

   data Op = Aop Aop | Bop Bop
   data Aop = Minus | Plus | Mul
   data Bop = LT | GT


It's a long story. The short version is that the above will  
complicate my AST a whole lot. I had it this way before.


Thanks, Joel

--
http://wagerlabs.com/





___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Morphing ASTs and scrapping boilerplate code

2007-04-19 Thread Joel Reymont

Folks,

I'm transforming ASTs as part of my compiler from one language into  
another. The source AST is a list of statements whereas the target  
AST is a class definition.


type Object a = State Obj a

data Obj
= Object
  { objSym :: Integer -- starting # for gensym
  , objVars :: M.Map String VarDecl
  , objProps :: M.Map String PropDecl
  , objMeths :: M.Map String MethodDecl
  }
deriving (Show, Eq)

I'm using a state monad and the transformations are supposed to  
update the state (object) as needed to add variables, methods, etc.


class Morpher a b | a - b where
morph :: a - Object b

I have a lot of boilerplate code like this and wonder how I can  
scrape it.


instance Morpher Type C.Type where
morph TyInt = return C.TyInt
morph TyFloat = return C.TyFloat
morph TyStr = return C.TyStr
morph TyBool = return C.TyBool
morph TyColor = return C.TyColor
morph TyStyle = return C.TyStyle
morph (TyList ty) = liftM C.TyList (morph ty)
morph (TyArray ty) = liftM C.TyArray (morph ty)
morph (TySeries ty) = liftM C.TySeries (morph ty)
morph (TyInput ty) = liftM C.TyProp (morph ty)
morph (TyRef ty) = liftM C.TyRef (morph ty)
morph TyUnit = return C.TyUnit
morph TyPrintDest = return C.TyPrintDest

Notice that I'm calling a constructor of the same name in a different  
module ... unless it's an exception.


instance Morpher BackRef C.Expr where
morph Now = C.Int 0
morph (BarsBack e) = morph e

instance Morpher DataRef C.Expr where
morph (DS x) = C.Int x

How can I reduce the boilerplate here?

Thanks, Joel

--
http://wagerlabs.com/





___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Re: Morphing ASTs and scrapping boilerplate code

2007-04-19 Thread Joel Reymont
Just to clarify, I really liked the SYB solution to my previous issue  
with stripping token locations. It looked like this:


strip :: (Data a) = a - a
strip = everywhere (mkT f)
where f (TokenPos a _) = a
  f x = x

In the general AST transformation case, my constructor name is the  
same and so is the number of arguments. So, yes, it's a different  
type but it's a derivative of Data and Typeable just like the  
original type.


Conceptually, I want to lookup the new type from a given module,  
using the same constructor name as the original type. Then I want to  
apply morph to every argument of the source constructor and give the  
resulting values to the new constructor.


Lastly, I would like to write pattern matches for special cases (see  
TokenPos above) and write out the transformation by hand. My ASTs are  
quite large and there aren't that many special cases.


Thanks, Joel

On Apr 19, 2007, at 5:11 PM, Joel Reymont wrote:


instance Morpher Type C.Type where

...

morph (TyList ty) = liftM C.TyList (morph ty)
morph (TyArray ty) = liftM C.TyArray (morph ty)
morph (TySeries ty) = liftM C.TySeries (morph ty)
morph (TyInput ty) = liftM C.TyProp (morph ty)
morph (TyRef ty) = liftM C.TyRef (morph ty)
morph TyUnit = return C.TyUnit
morph TyPrintDest = return C.TyPrintDest


--
http://wagerlabs.com/





___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] SYB and opaque types

2007-04-18 Thread Joel Reymont
Suppose I need to manually derive Data and Typeable for SourcePos  
from Parsec to make sure my code compiles. I won't actually be  
running the code I manually derive since the constructor that  
includes SourcePos will be skipped.


With Neil Mitchell's (and #haskell) help I'm doing this to strip  
token locations from my AST:


import Data.Generics
import qualified Text.ParserCombinators.Parsec as P

instance Data SourcePos where
gfoldl r k x = k x

typename_SourcePos = mkTyCon SourcePos

instance Typeable SourcePos
where typeOf _ = mkTyConApp typename_SourcePos ([])

strip = everywhere (mkT f)
where f (TokenPos a _) = a
  f x = x

I know that the warnings about gunfold, toConstr and dataTypeOf are  
harmless but how would I define them to avoid the warnings?


Also, the definition of strip above requires -fno-monomorphism- 
restriction. Should I not worry about it? The code runs just fine,  
locations are being stripped and tests pass.


Thanks, Joel

--
http://wagerlabs.com/





___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Zero-arity tests in QuickCheck and displaying expected result

2007-04-17 Thread Joel Reymont


On Apr 17, 2007, at 9:31 AM, Ketil Malde wrote:

Prelude Test.QuickCheck let prop0 = List.sort [3,2,1] == [1,2,3]  
in quickCheck prop0

OK, passed 100 tests.


My point is to be able to see that result generated was X and that it  
did not match expected Y, where both X and Y are printed out.


--
http://wagerlabs.com/





___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Zero-arity tests in QuickCheck and displaying expected result

2007-04-16 Thread Joel Reymont


On Apr 16, 2007, at 9:29 PM, Donald Bruce Stewart wrote:


It's interesting to note that QuickCheck generalises unit testing:
zero-arity QC properties are exactly unit tests.


I don't think this works very well. I rely quite heavily on being  
able to compare expected output with test results and QC does not  
seem to provide for this feature when tests are zero arity.


Am I missing something?

Thanks, Joel

--
http://wagerlabs.com/




___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Re: Zero-arity tests in QuickCheck and displaying expected result

2007-04-16 Thread Joel Reymont

Are there any examples of such custom drivers?

On Apr 16, 2007, at 10:09 PM, Donald Bruce Stewart wrote:


That's just the default driver. Plenty of custom drivers exist which
compare the output. The QC driver is just a function you implement,
after all.


--
http://wagerlabs.com/





___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Zero-arity tests in QuickCheck and displaying expected result

2007-04-16 Thread Joel Reymont
That's what HUnit does but it's enticing to be able to standardize on  
QuickCheck for all of your testing.


On Apr 16, 2007, at 10:11 PM, Lennart Augustsson wrote:


Why can't you just do 'f 1 2 3 == (4, 5, 6, 7)' to test f?


--
http://wagerlabs.com/





___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Parallel executing of actions

2007-04-15 Thread Joel Reymont


On Apr 15, 2007, at 8:23 PM, Spencer Janssen wrote:


parSequence_ xs = do
m - newEmptyMVar
mapM_ (\x - forkIO x  putMVar m ()) xs
replicateM_ (length xs) (takeMVar m)


mapM_ above spawns (length xs) threads blocking on a single lock,  
right?


replicateM_ then makes sure that the lock is unlocked as many times  
as threads spawned, right?


Since all the threads block on a single MVar how do they run in  
parallel?


Thanks, Joel

--
http://wagerlabs.com/





___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Type checking with Haskell

2007-04-12 Thread Joel Reymont

Folks,

The ghc/compiler/typecheck directory holds a rather large body of  
code and quick browsing through did not produce any insight.


How do you implement type checking in haskell?

Assume I have an Expr type with a constructor per type and functions  
can take lists of expressions. Do I create a function taking an Expr,  
pattern-matching on appropriate constructor and returning True on a  
match and False otherwise?


Thanks, Joel

--
http://wagerlabs.com/





___
Haskell-Cafe mailing list
[EMAIL PROTECTED]
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Type checking with Haskell

2007-04-12 Thread Joel Reymont


On Apr 12, 2007, at 1:07 PM, Stefan Holdermans wrote:

You might want to check out Typing Haskell in Haskell [1] by Mark  
P. Jones.


Must be _the_ paper as Don suggested it as well.

I also looked at my copy of Andrew Appel's compilers in ML book and  
realized that I should be going about it differently than I thought,  
i.e. figuring out and returning the type of an expression rather than  
matching constructors. Oh, well.


Thanks, Joel

--
http://wagerlabs.com/





___
Haskell-Cafe mailing list
[EMAIL PROTECTED]
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Typing non-Haskell in Haskell

2007-04-12 Thread Joel Reymont
I feel I should set aside a Friday of every week just to read the  
Haskell papers :-).


After skimming through Typing Haskell in Haskell I have a couple of  
questions...


Are type constructors (TyCon) applicable to Haskell only? Mine is a  
Pascal-like language.


How would I type Pascal functions as opposed to Haskell ones? It  
seems that the approach is the same and I still need TyCon (-).


Thanks, Joel

--
http://wagerlabs.com/





___
Haskell-Cafe mailing list
[EMAIL PROTECTED]
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Type checking with Haskell

2007-04-12 Thread Joel Reymont

Thanks Stefan!

On Apr 12, 2007, at 3:00 PM, Stefan O'Rear wrote:


Your problem, as I understand it, is even simpler than most since
there are no higher order functions and no arguments.


I do have functions and arguments but I don't have HOF.


(That said, it would probably be better to fuse parsing and type
checking in this case so that you do not need to track source
positions.)


I'm not sure how to do this, quite honestly. The language is  
dynamically typed so I have to infer variable types from their usage,  
function return types from what is assigned to the function name  
(last assignment in program, Fun = xxx). I also have to infer if  
variables are of a series type by checking if any references are made  
to the previous values of those variables.


I don't think it's possible to fuse type checking with parsing here.

--
http://wagerlabs.com/





___
Haskell-Cafe mailing list
[EMAIL PROTECTED]
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Type checking with Haskell

2007-04-12 Thread Joel Reymont


On Apr 12, 2007, at 3:00 PM, Stefan O'Rear wrote:

Also, GHC runs typechecking *before* desugaring, apparently  
thinking error messages

are more important than programmer sanity :)


What would be the benefit of running type checking after desugaring?

--
http://wagerlabs.com/





___
Haskell-Cafe mailing list
[EMAIL PROTECTED]
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Left-factoring with Parsec

2007-04-12 Thread Joel Reymont

How does

expr = b a*

translate back into the grammar? Assuming that I had b, c, d...

expr = b | c | d | many (do { symbol :; expr; symbol :;  
expr })


Like this?

Thanks, Joel

On Apr 11, 2007, at 8:56 PM, Lennart Augustsson wrote:

I presume your grammar has other clauses for expr, otherwise the  
loop is inevitable.

Assuming you have other clauses you can always left-factor.

Here's how those of us with weak memory can remember how to do it:

Say that you have

  expr ::= expr : expr : expr
 | b
Let's call the part from the first : a, since it doesn't matter  
what it is.  So we have

  expr ::= expr a | b
Let's call expr x, and just change notation slightly
  x = x a + b
Now use high school algebra
  x = x*a + b
  x - x*a = b
  x*(1-a) = b
  x = b / (1-a)
  x = b * 1/(1-a)
Now you have to remember that the Taylor series expansion of 1/(1- 
a) is

  1/(1-a) = 1 + a + a^2 + a^3 + a^4 + ...

OK, now put your grammar hat back on.  What's
  1 | a | aa | aaa |  | ...
it's just an arbitrary number of a:s, i.e., a* (or 'many a' in  
parsec).

So finally
  expr = b a*

-- Lennart

On Apr 11, 2007, at 18:15 , Joel Reymont wrote:


Suppose I have expr = expr : expr : expr.

Can the above be left-factored to fail on empty input so that my  
parser doesn't go into a loop?


Thanks, Joel

--
http://wagerlabs.com/





___
Haskell-Cafe mailing list
[EMAIL PROTECTED]
http://www.haskell.org/mailman/listinfo/haskell-cafe




--
http://wagerlabs.com/





___
Haskell-Cafe mailing list
[EMAIL PROTECTED]
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Left-factoring with Parsec

2007-04-11 Thread Joel Reymont

Suppose I have expr = expr : expr : expr.

Can the above be left-factored to fail on empty input so that my  
parser doesn't go into a loop?


Thanks, Joel

--
http://wagerlabs.com/





___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Skipping keywords with Parsec

2007-04-11 Thread Joel Reymont
Is there a way to have any Parsec combinator skip a certain set of  
keywords?


I tried lexeme = P.lexeme lexer . (skip ) but I don't think lexeme  
is called for every keyword.


Thanks, Joel

--
http://wagerlabs.com/





___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Re: Skipping keywords with Parsec

2007-04-11 Thread Joel Reymont
Just in case I wasn't clear enough, I'm asking about skipping  
keywords represented by the skip combinator that can be located  
anywhere within the input.


I do know about skipMany and skipMany1, in fact skip is defined in  
terms of these.


On Apr 11, 2007, at 9:04 PM, Joel Reymont wrote:

Is there a way to have any Parsec combinator skip a certain set of  
keywords?


I tried lexeme = P.lexeme lexer . (skip ) but I don't think  
lexeme is called for every keyword.


--
http://wagerlabs.com/





___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Parsec: Help needed with simple parser

2007-04-10 Thread Joel Reymont


On Apr 10, 2007, at 3:42 AM, Albert Y. C. Lai wrote:


Does option help? Like:


It did, together with a couple of 'try's.

Thanks, Joel

--
http://wagerlabs.com/





___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Type checking and locating token with Parsec

2007-04-10 Thread Joel Reymont

Folks,

Imagine a language where Num + Num yields a Num and Str + Num yields  
a Str but Num + Str should not be allowed.


I implemented parsing for such a language in OCaml with a yacc-based  
parser without an additional type-checking pass, entirely within the  
yacc grammar. I tried to take such an approach with Parsec but hit  
the roadblock with buildExpressionParser since it returns the same  
type as the token parser given to it.


Rather than have numerical expressions, string expressions, etc., as  
separate types, I simplified things down to a single expression type  
that holds my booleans, strings and numbers. I now need to implement  
type checking of my parsed AST.


The main issue is error reporting. I'm not sure where to get token  
location with Parsec and how to elegantly embed it in my AST.


Has anyone implemented type checking on top of a Parsec-based parser?

How did you locate your tokens?

Thanks, Joel

--
http://wagerlabs.com/





___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Grabbing list of functions from current module

2007-04-09 Thread Joel Reymont

Folks,

Does anyone have code that can grab a list of functions named with a  
certain prefix from the current (or given) module? I want to find  
functions named, say, ast_* and produce a list of tuples like  
(input1, ast_input1).


Thanks, Joel

--
http://wagerlabs.com/





___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Grabbing list of functions from current module

2007-04-09 Thread Joel Reymont

Mea culpa! I meant Template Haskell code :-).

Thanks John!

On Apr 9, 2007, at 2:02 PM, John Meacham wrote:


sed -ne 's/^ast_\([a-z0-9_A-Z]\+\).*$/(\1,ast_\1)/p'  File.hs

note the two occurances of 'ast_'.


--
http://wagerlabs.com/





___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Parsec: buildExpressionParser of a different type than parsed term

2007-04-09 Thread Joel Reymont

Folks,

I'm trying to parse NumExpr  NumExpr (example) which should return a  
logical expression while parsing numeric terms. I can't figure out  
how to make buildExpressionParser do this for me since it takes the  
type of the term parser given to it. If I supply a parser for numeric  
terms then I cannot return a logical expression.


How can this be resolved?

Note that I do not want to put all expressions into the same Expr  
type since it makes generating valid random ASTs with QuickCheck  
impossible.


Thanks, Joel

--
http://wagerlabs.com/





___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Parsec: buildExpressionParser of a different type than parsed term

2007-04-09 Thread Joel Reymont

Albert,

On Apr 10, 2007, at 12:19 AM, Albert Y. C. Lai wrote:

As you probably suspect, one single use of buildExpressionParser  
cannot accomplish it. It is equivalent to the problem of  
homogeneous lists.


The issue is that I need buildExpressionParser to parse numerical  
expression but return logical ones, i.e.


data CondExpr
  = CondExpr Op NumExpr NumExpr

The way b-E-P is set up it wants NumExpr to be its return type and  
thus I cannot return a CondExpr. I'm still scratching my head but in  
all likehood I'll have to hack a custom version of b-E-P.


Thanks, Joel

--
http://wagerlabs.com/





___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Parsec: Help needed with simple parser

2007-04-09 Thread Joel Reymont

Folks,

I wrote a parser for what should be a simple expression but it's not  
working. Any help is appreciated!


My expression is x + 1 where x can be either Close, or Close[N]  
or Close[N] of DataM where N and M are positive integers. What  
happens in my case is that 1 + x parses fine but x + 1 doesn't. In  
fact, I would be fine with parsing Close + such that it ignores the  
plus and returns the parse.


Thanks, Joel

--
http://wagerlabs.com/





___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] MPTC and type classes issue (polymorphic '+')

2007-04-07 Thread Joel Reymont

Folks,

I'm trying to save time when typing in my ASTs so I thought I would  
create a Plus class like this (I do hide the one from Prelude)


class PlusClass a b c | a b - c where
(+) :: a - b - c

{-
instance (Integral a, Integral b) = PlusClass a b Expr where
a + b = NumExpr (NumOp Plus (Int (fromIntegral a)) (Int  
(fromIntegral b)))


instance Integral a = PlusClass a Double Expr where
a + b = NumExpr (NumOp Plus (Int (fromIntegral a)) (Double b))
-}

instance PlusClass Integer Integer Expr where
a + b = NumExpr (NumOp Plus (Int a) (Int b))

instance PlusClass Double Integer Expr where
a + b = NumExpr (NumOp Plus (Double a) (Int b))

instance PlusClass NumExpr NumExpr Expr where
a + b = NumExpr (NumOp Plus a b)

instance PlusClass Integer NumExpr Expr where
a + b = NumExpr (NumOp Plus (Int a) b)

instance PlusClass  NumExpr Integer Expr where
a + b = NumExpr (NumOp Plus a (Int b))

instance PlusClass String String Expr where
a + b = StrExpr (StrOp StrPlus (Str a) (Str b))

NumExpr and StrExpr return Expr whereas Int, Double return NumExpr  
and Str returns StrExpr.


This is all so that I could type in

input2 =
[ InputDecs [ inp emaLength TyNumber (20 + 40) ] ]

Still, I get the following error

Easy/Test/ParserAST.hs:76:44:
No instance for (PlusClass t t1 Expr)
  arising from use of `+' at Easy/Test/ParserAST.hs:76:44-50
Possible fix: add an instance declaration for (PlusClass t t1 Expr)
In the third argument of `inp', namely `(20 + 40)'
In the expression: inp emaLength TyNumber (20 + 40)
In the first argument of `InputDecs', namely
`[inp emaLength TyNumber (20 + 40)]'

and get an overlapped instances error if I uncomment the top portion.

Any suggestions on how to resolve this?

Thanks, Joel

--
http://wagerlabs.com/





___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] MPTC and type classes issue (polymorphic '+')

2007-04-07 Thread Joel Reymont

Pepe,

On Apr 7, 2007, at 1:31 PM, Pepe Iborra wrote:

 input2 = [ InputDecs [ inp emaLength TyNumber ((20::Integer) +  
(40::Integer)) ] ]


Thank you for your suggestion! I'm trying to make my AST definition  
as succinct as possible, though, so I would really love to have 20 +  
40. The issue is confined to a single module used during testing.


Thanks, Joel

--
http://wagerlabs.com/





___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] MPTC and type classes issue (polymorphic '+')

2007-04-07 Thread Joel Reymont

This is the related paste:

http://hpaste.org/1291#a9

--
http://wagerlabs.com/





___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] MPTC and type classes issue (polymorphic '+')

2007-04-07 Thread Joel Reymont

Pepe,

On Apr 7, 2007, at 2:01 PM, Pepe Iborra wrote:

And without the Integral assumption, you cannot define your  
instance. So what I would do is to create a thin wrapper:


i = id :: Integer - Integer

and write:

 input2 = [ InputDecs [ inp emaLength TyNumber ((i 20) + (i  
40)) ] ]


That's what I did but I'm driving to make it even simpler.

I would like to add various permutations of Integer, Double and  
NumExpr, as well as String and StrExpr. This includes Integer/ 
Integer, Integer/Double, Double/NumExpr, etc.


This is standalone code, also at http://hpaste.org/1291#a12

{-# OPTIONS -fglasgow-exts -fallow-overlapping-instances #-}

import Prelude hiding ( id, (+), (-), (/), (*), (), GT, EQ, LT )

newtype VarIdent = VarIdent String

instance Show VarIdent

instance Eq VarIdent

data NumExpr
= Int Integer
| Double Double
| NumOp NumOp NumExpr NumExpr

data StrExpr
= Str String
| StrOp StrOp StrExpr StrExpr

data Expr
= NumExpr NumExpr
| StrExpr StrExpr

data Type = TyNumber | TyString

data NumOp = Plus | Minus -- ...

data StrOp = StrPlus

data Statement
= Skip
| InputDecs [InputDecl]

data InputDecl
= InputDecl VarIdent Type Expr

class PlusClass a b c | a b - c where
(+) :: a - b - c

-- instance PlusClass a b c = PlusClass b a c

instance (Integral a, Integral b) = PlusClass a b Expr where
a + b = NumExpr (NumOp Plus (Int (fromIntegral a)) (Int  
(fromIntegral b)))


instance Integral a = PlusClass a Double Expr where
a + b = NumExpr (NumOp Plus (Int (fromIntegral a)) (Double b))

instance PlusClass Integer Integer Expr where
a + b = NumExpr (NumOp Plus (Int a) (Int b))

instance PlusClass Double Integer Expr where
a + b = NumExpr (NumOp Plus (Double a) (Int b))

instance PlusClass NumExpr NumExpr Expr where
a + b = NumExpr (NumOp Plus a b)

instance PlusClass Integer NumExpr Expr where
a + b = NumExpr (NumOp Plus (Int a) b)


-- and the functions

id = VarIdent

inp x ty e = InputDecl (id x) ty e

input2 =
[ InputDecs [ inp emaLength TyNumber (20 + 40) ] ]



--
http://wagerlabs.com/





___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] MPTC and type classes issue (polymorphic '+')

2007-04-07 Thread Joel Reymont


On Apr 7, 2007, at 2:01 PM, Pepe Iborra wrote:


So what I would do is to create a thin wrapper:

i = id :: Integer - Integer

and write:

 input2 = [ InputDecs [ inp emaLength TyNumber ((i 20) + (i  
40)) ] ]


I do it like this and it does save typing. It's not bad so I'll stick  
to it for now:


id = VarIdent

d = Double
i = Int
b = Bool
s = Str

d' = NumExpr . d
i' = NumExpr . i
b' = CondExpr . b
s' = StrExpr . s

n = NumExpr

(+) a b = NumExpr (NumOp Plus a b)

This is much less verbose than my OCaml version anyway.

--
http://wagerlabs.com/





___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] MPTC and type classes issue (polymorphic '+')

2007-04-07 Thread Joel Reymont


On Apr 7, 2007, at 4:16 PM, Stefan O'Rear wrote:


You can probably use -fallow-incoherent-instances for this.  It has a
scary name on purpose since it doesn't usually do what you think it
should...  My (very limited!) understanding of type checking
algorithms says that in this case, the worst that can fail is an extra
call to fromInteger :: Integer - Integer.  Big deal.


It only works until I add instance declarations for Fractional.

Thanks, Joel

--
http://wagerlabs.com/





___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] How can I refactor this code?

2007-04-06 Thread Joel Reymont

http://hpaste.org/127

It looks quite ugly to me so any help is appreciated!

Thanks in advance, Joel

--
http://wagerlabs.com/


___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Re: How can I refactor this code?

2007-04-06 Thread Joel Reymont

That would be http://hpaste.org/1278, my apologies!

--
http://wagerlabs.com/





___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Automatic derivation (TemplateHaskell?)

2007-04-05 Thread Joel Reymont

Stefan,

Data.Derive is a most awesome piece of code!

Is there soemething in DrIFT that you did not like that made you  
write it?


Thanks a lot!

On Apr 5, 2007, at 12:48 AM, Stefan O'Rear wrote:


Data.Derive can do this.  In an attempt to avoid munging the relevent
files they are attached.


--
http://wagerlabs.com/





___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: Re[2]: [Haskell-cafe] Automatic derivation (TemplateHaskell?)

2007-04-05 Thread Joel Reymont

Following tells me that Data.Derive.Peephole was built.

ar t dist/build/libHSderive-0.1.a says Derive.o is there.

ghc-pkg -l
/opt/local/lib/ghc-6.6/package.conf:
Cabal-1.1.6, FilePath-0.11, GLUT-2.0, HUnit-1.1, OpenGL-2.1,
QuickCheck-1.0, base-2.0, cgi-2006.9.6, derive-0.1, fgl-5.2,
(ghc-6.6), haskell-src-1.0, haskell98-1.0, html-1.0, mtl-1.0,
network-2.0, parsec-2.0, readline-1.0, regex-base-0.71,
regex-compat-0.71, regex-posix-0.71, rts-1.0, stm-2.0,
template-haskell-2.0, time-1.0, unix-1.0, xhtml-2006.9.13

derive-1.0 is in the list of packages.

ghc --make FunParser.hs

FunParser.hs:4:7:
Could not find module `Data.Derive.Peephole':
  Use -v to see a list of the files searched for.

I'm baffled again.

---
runhaskell Setup.hs build
Preprocessing library derive-0.1...
Preprocessing executables for derive-0.1...
Building derive-0.1...
[1 of 9] Compiling Data.Derive.FixedPpr ( Data/Derive/FixedPpr.hs,  
dist/build/Data/Derive/FixedPpr.o )
[2 of 9] Compiling Data.Derive  ( Data/Derive.hs, dist/build/Data/ 
Derive.o )
[3 of 9] Compiling Data.Derive.SYB  ( Data/Derive/SYB.hs, dist/build/ 
Data/Derive/SYB.o )
[4 of 9] Compiling Data.Derive.TH   ( Data/Derive/TH.hs, dist/build/ 
Data/Derive/TH.o )
[5 of 9] Compiling Data.Derive.BinaryDefer ( Data/Derive/ 
BinaryDefer.hs, dist/build/Data/Derive/BinaryDefer.o )
[6 of 9] Compiling Data.Derive.Eq   ( Data/Derive/Eq.hs, dist/build/ 
Data/Derive/Eq.o )
[7 of 9] Compiling Data.Derive.Peephole ( Data/Derive/Peephole.hs,  
dist/build/Data/Derive/Peephole.o )
[8 of 9] Compiling Data.Derive.Binary ( Data/Derive/Binary.hs, dist/ 
build/Data/Derive/Binary.o )
[9 of 9] Compiling Data.Derive.Play ( Data/Derive/Play.hs, dist/build/ 
Data/Derive/Play.o )

ar: creating archive dist/build/libHSderive-0.1.a
[1 of 1] Compiling Main ( Derive.hs, dist/build/derive/ 
derive-tmp/Main.o )

Linking dist/build/derive/derive ...

sudo runhaskell Setup.hs install
Installing: /usr/local/lib/derive-0.1/ghc-6.6  /usr/local/bin  
derive-0.1...

Registering derive-0.1...
Reading package info from .installed-pkg-config ... done.
Saving old package config file... done.
Writing new package config file... done.


--
http://wagerlabs.com/





___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Automatic derivation (TemplateHaskell?)

2007-04-05 Thread Joel Reymont

Stefan,

What version of ghc are you using? Mine is 6.6.

Data/Derive/Play.hs:9:7:
Could not find module `Control.Monad.State':
  it is a member of package mtl-1.0, which is hidden

I commented out that import line.

Preprocessing library derive-0.1...
Preprocessing executables for derive-0.1...
Building derive-0.1...
[1 of 9] Compiling Data.Derive.FixedPpr ( Data/Derive/FixedPpr.hs,  
dist/build/Data/Derive/FixedPpr.o )
[2 of 9] Compiling Data.Derive  ( Data/Derive.hs, dist/build/Data/ 
Derive.o )
[3 of 9] Compiling Data.Derive.SYB  ( Data/Derive/SYB.hs, dist/build/ 
Data/Derive/SYB.o )
[4 of 9] Compiling Data.Derive.TH   ( Data/Derive/TH.hs, dist/build/ 
Data/Derive/TH.o )


Data/Derive/TH.hs:25:26:
No instance for (Functor Q)
  arising from use of `fmap' at Data/Derive/TH.hs:25:26-31
Possible fix: add an instance declaration for (Functor Q)
In the first argument of `(.)', namely `fmap f'
In the expression: (fmap f) . deriveOne
In the definition of `derive':
derive (Derivation f _) = (fmap f) . deriveOne

This I don't know how to deal with.

Thanks, Joel

--
http://wagerlabs.com/





___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Automatic derivation (TemplateHaskell?)

2007-04-05 Thread Joel Reymont


On Apr 5, 2007, at 11:04 AM, Joel Reymont wrote:

This is in Language.Haskell.TH.Syntax which is imported at the top  
of Data/Derive/TH.hs so I don't understand the cause of the error


Apparently instance Functor Q was added to 6.6 very recently and it's  
not in MacPorts yet.


I decided to throw down the gauntlet and run 6.7 instead.

--
http://wagerlabs.com/





___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Automatic derivation (TemplateHaskell?)

2007-04-05 Thread Joel Reymont

That did it, thanks!

On Apr 5, 2007, at 12:07 PM, Twan van Laarhoven wrote:


 instance Functor Q where
 fmap = liftM


--
http://wagerlabs.com/





___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: Re[2]: [Haskell-cafe] Automatic derivation (TemplateHaskell?)

2007-04-05 Thread Joel Reymont

Installed derive, trying to load it with ghci -package derive

Loading package base ... linking ... done.
Loading package template-haskell ... linking ... done.
Loading package FilePath-0.11 ... linking ... done.
ghc-6.6:
unknown symbol `_derivezm0zi1_DataziDeriveziPeephole_zdf7_closure'
Loading package derive-0.1 ... linking ... ghc-6.6: unable to load  
package `derive-0.1'


What am I doing wrong?

Thanks, Joel

--
http://wagerlabs.com/





___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Automatic derivation (TemplateHaskell?)

2007-04-05 Thread Joel Reymont
This is in Language.Haskell.TH.Syntax which is imported at the top of  
Data/Derive/TH.hs so I don't understand the cause of the error


instance Functor Q where
  fmap f (Q x) = Q (fmap f x)

Copying the above into TH.hs gives me

Preprocessing library derive-0.1...
Preprocessing executables for derive-0.1...
Building derive-0.1...
[4 of 9] Compiling Data.Derive.TH   ( Data/Derive/TH.hs, dist/build/ 
Data/Derive/TH.o )


Data/Derive/TH.hs:23:10: Not in scope: data constructor `Q'

Data/Derive/TH.hs:23:17: Not in scope: data constructor `Q'

But Q is exported by Languave.Haskell.TH.Syntax !!!

Any suggestions?

Thanks, Joel

--
http://wagerlabs.com/





___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: Re[2]: [Haskell-cafe] Automatic derivation (TemplateHaskell?)

2007-04-05 Thread Joel Reymont
This is the exposed modules portion of derive.cabal. I had to remove  
the empty lines since Cabal was complaining about them. I suspect one  
of these lines had Data.Derive.Peephole in it.


Exposed-Modules:
Data.Derive
Data.Derive.FixedPpr

Data.Derive.SYB
Data.Derive.TH

Data.Derive.Binary
Data.Derive.BinaryDefer
Data.Derive.Eq
Data.Derive.Play

On Apr 5, 2007, at 12:46 PM, Joel Reymont wrote:


FunParser.hs:4:7:
Could not find module `Data.Derive.Peephole':
  Use -v to see a list of the files searched for.



--
http://wagerlabs.com/





___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Automatic derivation (TemplateHaskell?)

2007-04-05 Thread Joel Reymont
With derive compiled and installed I thought I would change the code  
a bit and try it...


ghci -fth -v0 -e '$( _derive_print_instance makeFunParser  
Foo )' baz.hs


baz.hs:30:3: Not in scope: `a1'

Any help is appreciated!

Thanks, Joel

---

FunParser.hs:

module FunParser where

import Data.Derive
import Data.Derive.Peephole
import Data.List

import Text.ParserCombinators.Parsec ( CharParser )

makeFunParser = Derivation drv FunParser

drv dat@(DataDef name arity ctors) =
simple_instance FunParser dat [funN parse [ sclause [] body ] ]
where
  body = l1 choice $ lst [ clause con | con - ctors ]
  clause con = l1 reserved (lit (trim (ctorName con)))
   : args con (ctorArity con)
  trim = reverse . takeWhile (/= '.') . reverse
  args ct 0 = return' (ctp ct 'a')
  args ct k = l1 char (lit '(') : args' ct k 0
  args'  ct remn seen = l0 parse
=: (('a' : show seen)
  -: args'' ct (remn-1) (seen+1))
  args'' ct 0 seen = l1 char (lit ')') : return' (ctp ct 'a')
  args'' ct k seen = l1 char (lit ',') : args' ct k seen

class FunParser a
where parse :: CharParser s a


baz.hs:

import Text.ParserCombinators.Parsec hiding ( parse )
import qualified Text.ParserCombinators.Parsec.Token as T
import Text.ParserCombinators.Parsec.Language( emptyDef )
import Data.Derive.TH
import FunParser

data NumExpr
= Int Integer
| Num Double

instance FunParser NumExpr where
parse = numExpr

data Foo
= Foo NumExpr

lexer = T.makeTokenParser emptyDef

identifier = T.identifier lexer
reserved = T.reserved lexer
integer = T.integer lexer
float = T.float lexer

numExpr :: GenParser Char a NumExpr
numExpr =
choice [ integer = return . Int
   , float = return . Num
   ]

$( derive makeFunParser ''Foo )


--
http://wagerlabs.com/





___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Automatic derivation (TemplateHaskell?)

2007-04-05 Thread Joel Reymont

Here's the output from -ddump-splices (thanks Saizan for the tip).

It's returning a1 instead of a0.

ghci -fth -e '$( _derive_print_instance makeFunParser Foo )'  
baz.hs -ddump-splices

baz.hs:1:0:
baz.hs:1:0: Splicing declarations
derive makeFunParser 'Foo
  ==
baz.hs:30:3-28
instance {FunParser Main.Foo} where
[]
{ parse = choice
[()
   (reserved ['F', 'o', 'o'])
   (()
  (char '(') ((=) parse (\ a0 - ()  
(char ')') (return (Main.Foo a1)] }


baz.hs:30:3: Not in scope: `a1'

--
http://wagerlabs.com/





___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Automatic derivation (TemplateHaskell?)

2007-04-05 Thread Joel Reymont

Shouldn't this work just as well?

numExpr =
choice [ try $ float = return . Num
   , integer = return . Int
   ]

It works on Foo(10.345) but not on Bar(10, 103.34).

On Apr 5, 2007, at 4:09 PM, Stefan O'Rear wrote:


numExpr :: GenParser Char a NumExpr
numExpr = do sg - lexeme sign
 nf - natOrFloat
 return $ either (Int . sg) (Nat . sg) nf


It seems silly that there is no signed version of natOrFloat
predefined, any Parsec experts?

Stefan


--
http://wagerlabs.com/





___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Which pretty printer?

2007-04-04 Thread Joel Reymont
Should I prefer Daan Leijen's pretty printer [1] to the Hughes-SPJ  
one that comes with GHC?


Has anyone looked at both and is able to tell the difference?

I need to pretty-print a Pascal-like language as well as C#.

Thanks, Joel

[1] http://www.cs.uu.nl/~daan/download/pprint/pprint.html

--
http://wagerlabs.com/





___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Re: Which pretty printer?

2007-04-04 Thread Joel Reymont

Also, are there examples of using either pretty printer?

On Apr 4, 2007, at 9:57 AM, Joel Reymont wrote:

Should I prefer Daan Leijen's pretty printer [1] to the Hughes-SPJ  
one that comes with GHC?


Has anyone looked at both and is able to tell the difference?

I need to pretty-print a Pascal-like language as well as C#.


--
http://wagerlabs.com/





___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] QuickCheck's co-arbitrary

2007-04-04 Thread Joel Reymont

Folks,

I understand that arbitrary defines the possible values.

How do I generally come up with co-arbitrary, though?

Would someone kindly explain the choice of co-arbitrary in the  
following cases, specially the very last bit with variant 1 .  
coarbitrary a?


instance Arbitrary Char where
arbitrary = elements ([' ', '\n', '\0'] ++ ['a'..'h'])
coarbitrary c = variant (fromEnum c `rem` 4)

instance Arbitrary Ordering where
arbitrary  = elements [LT, EQ, GT]
coarbitrary LT = variant 0
coarbitrary EQ = variant 1
coarbitrary GT = variant 2

instance Arbitrary a = Arbitrary (Maybe a) where
arbitrary= frequency [ (1, return Nothing)
 , (3, liftM Just arbitrary) ]
coarbitrary Nothing  = variant 0
coarbitrary (Just a) = variant 1 . coarbitrary a

Thanks, Joel

--
http://wagerlabs.com/





___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] QuickCheck: Arbitrary for a complex type

2007-04-04 Thread Joel Reymont
Suppose I have a type describing a statement and that I'm trying to  
make it an instance of arbitrary. The type looks like this:


data Statement
= InputDecs [InputDecl]
| VarDecs [VarDecl]
| ArrayDecs [ArrayDecl]
| Compound [Statement]
| Assign (VarIdent, Expr)
| ArrayAssign (VarIdent, [Expr], Expr)

Assuming that other types involved were instances of arbitrary, how  
do I write arbitrary for Statement?


Poking around various bits of source code I think that for a type  
like the following


data Style
= StyleValue Expr
| Solid
| Dashed
| Dotted
| Dashed2
| Dashed3
deriving Show

I can write

instance Arbitrary Style where
arbitrary = oneOf [ StyleValue . arbitrary,
elements [ Solid
 , Dashed
 , Dotted
 , Dashed2
 , Dashed3
 ]
  ]

I'm not sure if this is correct, though, so any help is appreciated!

Thanks in advance, Joel

--
http://wagerlabs.com/





___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Re: QuickCheck: Arbitrary for a complex type

2007-04-04 Thread Joel Reymont
I got this simple example working so I think I have my question  
answered.


Now I just have to learn to write generators of my own to produce  
valid and invalid input for my parser.


module Foo where

import Control.Monad
import System.Random
import Test.QuickCheck

data Foo
= Foo Int
| Bar
| Baz
  deriving Show

instance Arbitrary Foo where
coarbitrary = undefined
arbitrary   = oneof [ return Bar
, return Baz
, liftM Foo arbitrary
]

gen' rnd = generate 1 rnd $ vector 5 :: [Foo]

gen =
do { rnd - newStdGen
   ; return $ gen' rnd
   }

--
http://wagerlabs.com/





___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Re: QuickCheck: Arbitrary for a complex type

2007-04-04 Thread Joel Reymont

One last bit then...

My identifiers should start with letter | char '_' and the tail  
should be alphaNum | char '_'.


I guess I can use choose and oneof to produce the right set of  
characters but how do I combine  the two into a single identifier of  
a given length (up to 20 chars, say)?


Thanks, Joel

On Apr 4, 2007, at 5:27 PM, Fawzi Mohamed wrote:

Great, just one thing that could be important : when you have  
recursive structures (like your Statement through Compound) be sure  
to use

sized (\mySize - ...)
as generator for arbitrary so that you can avoid infinite looping.


--
http://wagerlabs.com/





___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Automatic derivation (TemplateHaskell?)

2007-04-04 Thread Joel Reymont

Folks,

I have very uniform Parsec code like this and I'm wondering if I can  
derive it using TemplateHaskell or DrIFT or some other tool. Any ideas?


Note that

1) The reserved word matches the constructor

2) No arguments equals no parens

3) More than one argument is separated with a comma

4) For every invocation of numExpr, strExpr or boolExpr, the type of  
the constructor argument is NumExpr, StrExpr and BoolExpr respectively.


This is just a handful of functions and I have to tackle about 100  
more, thus my asking :-).


Thanks, Joel

---

strCall =
choice [ do { reserved NewLine
; return NewLine
}
   , do { reserved GetSymbolName
; return GetSymbolName
}
   , do { reserved ELDateToString
; arg1 - parens numExpr
; return $ ELDateToString arg1
}
   , do { reserved TextGetString
; arg1 - parens numExpr
; return $ TextGetString arg1
}
   , do { reserved Description
; return Description
}
   , do { reserved GetExchangeName
; return GetExchangeName
}
   , do { reserved LeftStr
; parens $ do { arg1 - strExpr
  ; comma
  ; arg2 - numExpr
  ; return $ LeftStr arg1 arg2
  }
}
   , do { reserved RightStr
; parens $ do { arg1 - strExpr
  ; comma
  ; arg2 - numExpr
  ; return $ RightStr arg1 arg2
  }
}
   , do { reserved LowerStr
; arg1 - parens strExpr
; return $ LowerStr arg1
}
   , do { reserved UpperStr
; arg1 - parens strExpr
; return $ UpperStr arg1
}
   , do { reserved Spaces
; arg1 - parens numExpr
; return $ Spaces arg1
}
   , do { reserved SymbolRoot
; return SymbolRoot
}
   , do { reserved MidStr
; parens $ do { arg1 - strExpr
  ; comma
  ; arg2 - numExpr
  ; comma
  ; arg3 - numExpr
  ; return $ MidStr arg1 arg2 arg3
  }
}
   , do { reserved NumToStr
; parens $ do { arg1 - numExpr
  ; comma
  ; arg2 - numExpr
  ; return $ NumToStr arg1 arg2
  }
}
   ]

--
http://wagerlabs.com/





___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] SmallCheck and parser testing

2007-04-03 Thread Joel Reymont

Folks,

I'm trying to figure out how to test a Parsec-based parser with  
Smallcheck [1]. My test AST is below and the goal is to return  
StyleValue Int here if the parser is fed an integer, or return  
Solid when parsing Solid, etc.


data Style
= StyleValue Expr
| Solid
| Dashed
| Dotted
| Dashed2
| Dashed3
deriving Show

I figure that the following is needed somehow:

instance Serial Style where
series = cons1 StyleValue . depth 0
 \/ cons0 Solid
 \/ cons0 Dashed
 \/ cons0 Dashed2
 \/ cons0 Dashed3
 \/ cons0 Dotted

My parser is 'style', so I would be passing it as p below

run p input =
case (parse p  input) of
  Left err - do { putStr parse error at 
 ; print err
 }
  Right x - x

How do I go from here to making sure my parser is valid?

I thought of the following property (thanks sjanssen)

prop_parse p s =
show (run p s) == s


but I don't know how to proceed from here.

Thanks, Joel

[1] http://www.cs.york.ac.uk/fp/darcs/smallcheck/

--
http://wagerlabs.com/





___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Keeping a symbol table with Parsec

2007-04-02 Thread Joel Reymont

Folks,

Are there any examples of keeping a symbol table with Parsec?

I'm translating a parser from OCaml and I do this

OUTPUT COLON ID LP NUMERIC_SIMPLE RP
  { add $3 TypNumOut; SimpleOutputDec ($3, Number) }

Meaning that if a keyword Output is followed by : and an identifier  
and then (NumericSimple) then add identifier to the symbol table as  
a Number and box it in a constructor.


Then in my lexer I do a lookup to check if I have seen this  
identifier and if I have seen one of type TypeNumOut I return the  
token NUM instead of ID. This ensures that I can have rules with the  
token NUM as opposed to ID everywhere.


How would I accomplish the same with Parsec, that is 1) update a  
symbol table and 2) check identifiers and return a different token?


Thanks, Joel

--
http://wagerlabs.com/





___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Keeping a symbol table with Parsec

2007-04-02 Thread Joel Reymont


On Apr 2, 2007, at 11:17 PM, Nicolas Frisby wrote:


Section 2.12 of the Parsec manual[1] discusses user state. It sounds
like that is what you are after.


Yes, thanks. My question is mostly about how to return a different  
token when the lexer finds an identifier that's already in the  
symbol table.


--
http://wagerlabs.com/





___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] questions about core

2007-02-12 Thread Joel Reymont


On Feb 12, 2007, at 5:45 AM, Matt Roberts wrote:


 - The hackathon videos,
 - A transformation-based optimiser for Haskell,
 - An External Representation for the GHC Core Language (DRAFT for  
GHC5.02), and

 - Secrets of the Glasgow Haskell Compiler inliner.


Matt, can you please post pointers to the above?

Thanks, Joel

--
http://wagerlabs.com/





___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] questions about core

2007-02-12 Thread Joel Reymont


On Feb 12, 2007, at 7:06 AM, Stefan O'Rear wrote:

We have Core because Simon lacks the patience to solve the halting  
problem and

properly perform effects analysis on STG.

We have STG because Simon lacks the patience to wait for the 6.6  
Simplifier to

finish naively graph-reducing every time.


Are these two different Simons? :-)

--
http://wagerlabs.com/





___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Lambada and connecting Haskell to a Weblogic server

2007-02-11 Thread Joel Reymont
Yep, don't have access to the Weblogic server. I'm re-evaluating my  
options, though, since I'm lazy by nature.


On Feb 11, 2007, at 12:30 PM, Neil Bartlett wrote:


Joel,

Implementing Java RMI in Haskell sounds like a nightmare. Why not  
use HTTP? You could easily write a wrapper Servlet that speaks XML  
or JSON over HTTP, and deploy that to the Weblogic server. Unless  
you don't have permission to deploy anything to that server for  
whatever reason.


--
http://wagerlabs.com/





___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Embedding ghc

2007-02-10 Thread Joel Reymont

Has anyone tried embedding ghc into their app?

How big are the resulting binaries?

Thanks, Joel

--
http://wagerlabs.com/





___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Haskell vs Ruby as a scripting language

2007-02-10 Thread Joel Reymont

Is anyone using Haskell as a scripting language in their app?

I'm thinking of viable it would be to embed ghc in a Mac (Cocoa) app.

TextMate [1] uses Ruby as the extension language and quite  
successfully at that. Everybody loves Ruby since it's simple. I need  
a trading systems language and I'm afraid the combination of ...  
everything that makes Haskell otherwise great will prove a drawback  
in my case.


What do you think?

Thanks, Joel

[1] http://macromates.com/

--
http://wagerlabs.com/





___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Haskell vs Ruby as a scripting language

2007-02-10 Thread Joel Reymont


On Feb 10, 2007, at 2:25 PM, Brian Smith wrote:

Is your application primarily written in Haskell? If not, you would  
have to
create an interface between that language and Haskell in order for  
your

Haskell programs to manipulate your domain objects and user interface.


It would be Objective-C and Haskell, the exact split yet unknown.

I think people would be happy if you did this because then there  
would be a

Haskell API for Cocoa, but it seems like a lot of work.


You already have this in HOC (http://hoc.sourceforge.net/)


My guess is that it
would be easier to do such bindings for Javascript due to its  
dynamic nature

and it being an object-oriented language. Also, several projects have
embedded Javascript successfully and so you would have many  
examples to base

your project on.


I don't see how this is different from Ruby.

Visual Haskell also embeds GHC (into Visual Studio). However,  
Visual Haskell

makes my Visual Studio unstable and often unresponsive.


I'm not sure this would apply to me as I'm on Mac OSX.


But, there were disadvantages too (e.g. I had to implement my
own lexer because doing doing it with GHC via IPC was too slow for
interactive use).


Well, yes, I would want syntax highlighting and formatting. I would,  
in fact, need a built-in Haskell IDE.


Also, I recommend looking into embedding YHC. I have not had a  
chance to use

it yet, but it looks like it is a better fit to an interpreter-only
embedding situation than GHC--with GHC, you are getting a lot more  
than you

seem to be asking for.


I would want to compile code as well. Compile bits of code 100 lines  
at a time and load them back into my app for execution. Does YHC  
compile and how efficiently?


Thanks, Joel

--
http://wagerlabs.com/





___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Lambada and connecting Haskell to a Weblogic server

2007-02-10 Thread Joel Reymont

Folks,

Where can I find Lambada these days and would it be of any use to me  
in trying to connect to a Weblogic server?


To make the long story short, my broker's Java software connects to a  
remote Weblogic server and I would like to do the same. I suppose  
this would require me to implement Java RMI in Haskell which is non- 
trivial.


I wonder if it would be easier for me to implement a Java server that  
talks to Weblogic and then connect to that server. What do you think?


Thanks, Joel

--
http://wagerlabs.com/





___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Parsec and Java

2007-02-10 Thread Joel Reymont

Folks,

Is there a Java parser implemented using Parsec?

Thanks, Joel

--
http://wagerlabs.com/





___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] How did you stumble on Haskell?

2007-02-03 Thread Joel Reymont

I'll go for the shortest story...

I stumbled upon Simon's Composing Financial Contracts paper, Simon  
was gracious enough to spend a fair bit of time on the phone with me.


The rest is history :-).

Joel

--
http://wagerlabs.com/





___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] A distributed and replicating native Haskell database

2007-02-02 Thread Joel Reymont

Folks,

Allegro Common Lisp has AllegroCache [1], a database built on B-Trees  
that lets one store Lisp objects of any type. You can designate  
certain slots (object fields) as key and use them for lookup. ACL  
used to come bundled with the ObjectStore OODBMS for the same purpose  
but then adopted a native solution.


AllegroCache is not distributed or replicating but supports automatic  
versioning. You can redefine a class and new code will store more (or  
less) data in the database while code that uses the old schema will  
merrily chug along.


Erlang [2] has Mnesia [3] which lets you store any Erlang term  
(object). It stores records (tuples, actually) and you can also  
designate key fields and use them for lookup. I haven't looked into  
this deeply but Mnesia is built on top of DETS (Disk-based Term  
Storage) which most likely also uses a form of B-Trees.


Mnesia is distributed and replicated in real-time. There's no  
automatic versioning with Mnesia but user code can be run to read old  
records and write new ones.


Would it make sense to build a similar type of a database for  
Haskell? I can immediately see how versioning would be much harder as  
Haskell is statically typed. I would love to extend recent gains in  
binary serialization, though, to add indexing of records based on a  
designated key, distribution and real-time replication.


What do you think?

To stimulate discussion I would like to ask a couple of pointed  
questions:


- How would you designate a key for a Haskell data structure?

- Is the concept of a schema applicable to Haskell?

Thanks, Joel

[1] http://franz.com/products/allegrocache/index.lhtml
[2] http://erlang.org/faq/t1.html
[3] http://erlang.org/faq/x1409.html

--
http://wagerlabs.com/





___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] A distributed and replicating native Haskell database

2007-02-02 Thread Joel Reymont


On Feb 2, 2007, at 3:06 PM, Paul Johnson wrote:

As a rule, storing functions along with data is a can of worms.  
Either you actually store the code as a BLOB or you store a pointer  
to the function in memory. Either way you run into problems when  
you upgrade your software and expect the stored functions to work  
in the new context.


ACache does not store code in the database. You cannot read the  
database unless you have your original class code. ACache may store  
the schema, i.e. the parent class names, slot names, etc.


Erlang also has a very disciplined approach to code updates, which  
presumably helps a lot when functions are stored.


No storing of code here either. What you store in Erlang is just  
tuples so there's no schema or class definition. No functions are  
stored since any Erlang code can fetch the tuples from Mnesia. You do  
need to have the original record definition around but this is just  
to be able to refer to tuple elements with field names rather name  
field position.


I very much admire Mnesia, even though I'm not an Erlang  
programmer. It would indeed be really cool to have something like  
that. But Mnesia is built on the Erlang OTP middleware. I would  
suggest that Haskell needs a middleware with the same sort of  
capabilities first. Then we can build a database on top of it.


Right. That would be a prerequisite.

The real headache is type safety. Erlang is entirely dynamically  
typed, so untyped schemas with column values looked up by name at  
run-time fit right in, and its up to the programmer to manage  
schema and code evolution to prevent errors. Doing all this in a  
statically type safe way is another layer of complexity and checking.


I believe Lambdabot does schema evolution.

Alternatively the protocol can be defined in a special purpose  
protocol module P, and A and B then import P. This is the approach  
taken by CORBA with IDL. However what happens if P is updated to  
P'? Does this mean that both A and B need to be recompiled and  
restarted simultaneously? Requiring this is a Bad Thing; imagine if  
every bank in the world had to upgrade and restart its computers  
simultaneously in order to upgrade a common protocol.


I would go for the middle ground and dump the issue entirely. Lets be  
practical here. When a binary protocol is updated, all code using the  
protocol needs to be updated. This would be good enough. It would  
suite me just fine too as I'm not yearning for CORBA, I just want to  
build a trading infrastructure entirely in Haskell.


There is still the possibility of a run-time failure at the  
protocol negotiation stage of course, if it transpires that the to  
processes have no common protocol.


So no protocol negotiation!

However there is a wrinkle here: what about pass through  
processes which don't interpret the data but just store and forward  
it. Various forms of protocol adapter fit this scenario, as does  
the database you originally asked about.


Any packet traveling over the wire would need to have a size,  
followed by a body. Any pass-through protocol can just take the  
binary blob and re-send it.


Thanks, Joel

--
http://wagerlabs.com/





___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Connected!

2007-02-01 Thread Joel Reymont

What part of Russia do you live in?

On Feb 1, 2007, at 1:23 PM, Bulat Ziganshin wrote:


Hello haskell-cafe,

i've just got ADSL connection here! it's slow (64k) and not cheap, but
at least it is completely different from dial-up i've used before


--
http://wagerlabs.com/





___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] proposal: HaBench, a Haskell Benchmark Suite

2007-01-28 Thread Joel Reymont


On Jan 28, 2007, at 8:51 AM, Andy Georges wrote:

it is nice to know that e.g., Data.ByteString performs as good as  
C, but is would be even nicer to see that large, real-life apps can  
reach that same performance.


What about using darcs as a benchmark? I heard people say it's slow.  
The undercurrent is that it's slow because it's written in Haskell.


--
http://wagerlabs.com/





___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


  1   2   3   4   5   >