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@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe