[Haskell-cafe] DSL for business logic

Bhinderwala, Shoeb SBhinderwala at wellington.com
Mon Oct 18 15:35:23 EDT 2004


I understand that there will be issues integrating with Java, but I want
to consider a Haskell solution nevertheless. 

Are monadic programming concepts essential to create a DSL. I am just
learning Haskell and haven't grasped fully the concepts of monadic
programming yet. 

Referring to Paul's paper "Modular Domain Specific Languages", it seems
like a DSEL in Haskell is just a plain Haskell program that uses
functions to model the business domain. I am referring to the DSEL for
gemoetric region analysis and Fran both of which look like code in
familiar Haskell syntax.

Our business problem is in the financial space where we have rules that
check compliance on portfolios. Some example rules are:

- The portfolio may not invest more than 40% in equity securities.
- The portfolio may not invest more than 5% in any sector relative to
the S&P500 index.
- The portfolio cannot buy any securities whose issuers are domiciled in
Japan.

Currently we have high level rule expressions that get mapped to
low-level code that embodies the business logic of checking the rules.
Essentially most of our rules do the following:
 1. Group, sort, and filter the portfolio's holdings. 
 2. Examine individual groups (also called 'buckets') and compute
aggregated values. Eg. percent market value of each bucket.
 3. Compare the value for each group with threshold values to check
compliance

I am wondering if is is a good idea to express the above logic in a
Haskell DSL by creating data types for Holding, Bucket, Portfolio, etc.

Would I be going on the right track by modelling a concentration rule
as:

  -- A concentration rule takes a list of Holdings and a list
  -- of filter rules and returns an aggregate number.
  conc :: [Holding] -> [holdingFilter] -> Float
  holdingFilter :: Holding -> Boolean

-- Shoeb 

-----Original Message-----
From: Paul Hudak [mailto:paul.hudak at yale.edu]
Subject: Re: [Haskell-cafe] Integrating Haskell into a J2EE environment

I wouldn't write off Haskell so quickly.  All of what Shoeb describes
concerning DSL issues might be much more easily solved in Haskell, and
will certainly be more flexible than a hard-wired approach.  The J2EE
interface might be ugly, but if the functionality needed is not too
great it might not be too bad.  Generally speaking, these kinds of apps
-- in this case "a DSL for high-level business rules" -- sounds like
just the sort of thing that Haskell is good for.

   -Paul

Doug Kirk wrote:
> You're going to spend alot of time marshalling between Java and 
> Haskell values, and you'll either have to do it via JNI or by using 
> pipes [as in System.exec("haskellprogram param param param")], both of

> ...
> 
> Take care,
> --doug
> 
> 
> On Oct 5, 2004, at 4:33 PM, Bhinderwala, Shoeb wrote:
> 
> Hi All,
> 
> I am new to Haskell and this mailing list.
> 
> We have a system that uses a custom high-level language to express 
> high-level business rules. Expressions in the high-level language get 
> compiled to Java bytecode. We express the grammar using BNF notation 
> as required by the javacc parser tool. This is then converted to an 
> AST using jjtree and from there we build the final Java code. Our 
> language could be considered a domain-specific language (DSL) and is 
> used by our business users to express very high-level business logic.
> The language currently is very limited - we support boolean logic, 
> function invocations and if-then statements. We want to convert it 
> into a more powerful scripting language so that even lower level 
> business logic can be expressed in it.
> 
> I came across a few papers that talk about writing a DSL with Haskell 
> as the underlying support language. How is this done. Is it possible 
> to create a sort of domain specific business scripting language 
> easily. How does that then compile to Haskell code. And how can the 
> Haskell code be invoked from Java.
> 
> Essentially, I am thinking if I could use a Haskell like DSL language 
> to express our business rule logic and then be able to integrate into 
> and invoke the logic from a J2EE app server environment. Has anybody 
> done anything like this with Haskell.
> 
> -- Shoeb


More information about the Haskell-Cafe mailing list