[Haskell-cafe] Design of a DSL in Haskell
Kim-Ee Yeoh
ky3 at atamo.com
Tue Dec 4 11:01:00 CET 2012
On Tue, Dec 4, 2012 at 4:53 PM, Joerg Fritsch <fritsch at joerg.cc> wrote:
> is a shallow embedded DSL == an internal DSL and a deeply embedded DSL ==
an external DSL or the other way around?
Roughly speaking, yes. But a deep DSL doesn't mean you've got to have a
parser << tokenizer << IO input. You can get a deep DSL merely from the
free monad construction.
-- Kim-Ee
On Tue, Dec 4, 2012 at 4:53 PM, Joerg Fritsch <fritsch at joerg.cc> wrote:
> Hi Tillmann,
>
> is a shallow embedded DSL == an internal DSL and a deeply embedded DSL ==
> an external DSL or the other way around?
>
> --Joerg
>
> On Dec 3, 2012, at 11:40 PM, Tillmann Rendel wrote:
>
> > Hi,
> >
> > Joerg Fritsch wrote:
> >> I am working on a DSL that eventuyally would allow me to say:
> >>
> >> import language.cwmwl
> >>
> >> main = runCWMWL $ do
> >>
> >> eval ("isFib::", 1000, ?BOOL)
> >>
> >>
> >> I have just started to work on the interpreter-function runCWMWL and I
> >> wonder whether it is possible to escape to real Haskell somehow (and
> >> how?) either inside ot outside the do-block.
> >
> > You can already use Haskell in your DSL. A simple example:
> >
> > main = runCWMWL $ do
> > eval ("isFib::", 500 + 500, ?BOOL)
> >
> > The (+) operator is taken from Haskell, and it is available in your DSL
> program. This use of Haskell is completely for free: You don't have to do
> anything special with your DSL implementation to support it. I consider
> this the main benefit of internal vs. external DSLs.
> >
> >
> > A more complex example:
> >
> > main = runCWMWL $ do
> > foo <- eval ("isFib::", 1000, ?BOOL)
> > if foo
> > then return 27
> > else return 42
> >
> > Here, you are using the Haskell if-then-else expression to decide which
> DSL program to run. Note that this example also uses (>>=) and return, so
> it only works because your DSL is monadic. Beyond writing the Monad
> instance, you don't have to do anything special to support this. In
> particular, you might not need an additional embed function if you've
> already implemented return from the Monad type class. I consider this the
> main benefit of the Monad type class.
> >
> > Tillmann
>
>
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20121204/5280a371/attachment-0001.htm>
More information about the Haskell-Cafe
mailing list