[Haskell-cafe] DSL implementation

31 views
Skip to first unread message

felipe zapata

unread,
Sep 17, 2014, 2:02:55 PM9/17/14
to haskel...@haskell.org
HI all,
as a part of a project for physical simulation, I'm was given the task to help with the implementation of an Small DSL that is a minimal functional language. Point is that this small language contains some dependent typed theory, because we want to be able to check statically the shapes of vector and matrices, among other things. Haskell of course seems the tool for the job.
But my boss insists that the implementation should be done in C, but I think that it is madness. 
Can someone please point me to relevant literature, discussions or general information that can help me to show my boss that Haskell is the right tool?

any help would be appreciated.

Felipe Z.

Tikhon Jelvis

unread,
Sep 17, 2014, 2:07:09 PM9/17/14
to felipe zapata, haskel...@haskell.org

One option to consider is using Haskell as the host language for your DSL but then generating either C or LLVM bytecode directly. Haskell has a few DSLs in this vein like Ivory, Copilot and Atom which you can look to for inspiration.

This can give you Haskell's expressiveness and type system coupled with the speed, portability and compatibility of C or LLVM.

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

Magnus Therning

unread,
Sep 17, 2014, 2:33:57 PM9/17/14
to haskel...@haskell.org
Why try to convince him? ;)

There is always the option of disregarding what the boss says and just
do it in Haskell and face the music later. I've done this kind of
thing a few times, but only when all of the following hold:

1. I am 100% sure I am right and the other party is wrong
2. I am confident I can tackle a large enough part of the problem and
have something to show before reaching a point of no return (i.e.
I must be able to show something that convincingly shows that I am
going down the correct path before reaching the point where
switching to the "inferior path" becomes impossible)
3. I feel safe enough in my employment that I can handle a
spectacular failure, or I don't care enough about my employment to
worry a spectacular failure

If you want to try to convince him I would urge you to not spend too
much time on the technical superiority of using Haskell to implement
the DSL. Instead you should spend time on finding out what makes your
boss suggest using C. Is it familiarity? Is it worry about
future maintenance? Is it just habit? C is almost *always* an
inferior choice so anyone arguing in favour of it is probably doing it
for emotional reasons, not technical! (Only slightly tongue-in
cheek.)

/M

--
Magnus Therning OpenPGP: 0xAB4DFBA4
email: mag...@therning.org jabber: mag...@therning.org
twitter: magthe http://therning.org/magnus

In a hierarchy, every employee tends to rise to his level of incompetence.
-- The Peter Principle

Dominic Steinitz

unread,
Sep 18, 2014, 2:13:09 AM9/18/14
to haskel...@haskell.org
You have looked at the latest HMatrix with its static guarantees:
Numeric.LinearAlgebra.Static? I think it is brilliant. It actually
caught a bug in my mathematical derivation. I had written out the
equations in LaTeX and then coded them up and couldn't understand why
I was getting a type error until I realised it was my derivation that
was wrong. Have a look here at its use:
http://idontgetoutmuch.wordpress.com/2014/09/09/fun-with-extended-kalman-filters-4/.

Dominic Steinitz

unread,
Sep 18, 2014, 5:11:17 AM9/18/14
to haskel...@haskell.org
I don't know if this is helpful but the example I gave also uses automatic
differentiation. Of course, one can get that in C++ using STAN.

Dr Christopher Anand

unread,
Sep 18, 2014, 9:18:30 AM9/18/14
to felipe zapata, haskel...@haskell.org
Hi Felipe,

We performed an (unplanned) experiment relevant to your case.  We developed a DSL in Haskell and a library of math functions while IBM was doing the same thing in C.


The C library was 4X slower, and less accurate.

More recently we have wrapped-up a prototype for type-safe physical models and there is a preprint and three example implementations which might be of help in constructing your own. 


Good luck explaining why Haskell is so good for DSLs.  You might find


helpful.

Christopher

Kyle Marek-Spartz

unread,
Sep 21, 2014, 9:32:05 PM9/21/14
to Dr Christopher Anand, felipe zapata, haskell-cafe
You may be interested in using C-DSL to generate your DSL’s output. It should keep your output readable.

https://bitbucket.org/jozefg/c-dsl

Kyle Marek-Spartz
 
 
 
 
 
On Sep 18, 2014, 8:18:10 AM, Dr Christopher Anand <ana...@mcmaster.ca> wrote:
Reply all
Reply to author
Forward
0 new messages