[Haskell-cafe] Design of a DSL in Haskell

Joerg Fritsch fritsch at joerg.cc
Mon Dec 3 16:25:06 CET 2012


Thanks Brent,

my question is basically how the function embed would in practice be implemented.

I want to be able to take everything that my own language does not have from the host language, ideally so that I can say:

evalt <- eval ("isFib::", 1000, ?BOOL))
case evalt of
           Left Str -> ....
           Right Str -> .... 


or so.
        
--Joerg

On Dec 3, 2012, at 4:04 PM, Brent Yorgey wrote:

> (Sorry, forgot to reply to the list initially; see conversation below.)
> 
> On Mon, Dec 03, 2012 at 03:49:00PM +0100, Joerg Fritsch wrote:
>> Brent,
>> 
>> I believe that inside the do-block (that basically calls my
>> interpreter) I cannot call any other Haskell function that are not
>> recognized by my parser and interpreter.
> 
> This seems to just require some sort of "escape mechanism" for
> embedding arbitrary Haskell code into your language.  For example a
> primitive
> 
>  embed :: a -> CWMWL a
> 
> (assuming CWMWL is the name of your monad).  Whether this makes sense,
> how to implement embed, etc. depends entirely on your language and
> interpreter.  
> 
> However, as you imply below, this may or may not be possible depending
> on the type a.  In that case I suggest making embed a type class method.
> Something like
> 
>  class Embeddable a where
>    embed :: a -> CWMWL a
> 
> I still get the feeling, though, that I have not really understood
> your question.
> 
>> I am also trying to learn how I could preserve state from one line
>> of code of my DSL to the next. I understand that inside the
>> interpreter one would use a combination of the state monad and the
>> reader monad, but could not find any non trivial example.
> 
> Yes, you can use the state monad to preserve state from one line to
> the next.  I am not sure what you mean by using a combination of state
> and reader monads.  There is nothing magical about the combination.
> You would use state + reader simply if you had some mutable state as
> well as some read-only configuration to thread through your
> interpreter.
> 
> xmonad is certainly a nontrivial example but perhaps it is a bit *too*
> nontrivial.  If I think of any other good examples I'll let you know.
> 
> -Brent
> 
>> 
>> 
>> On Dec 3, 2012, at 1:23 PM, Brent Yorgey wrote:
>> 
>>> On Sun, Dec 02, 2012 at 03:01:46PM +0100, Joerg Fritsch wrote:
>>>> This is probably a very basic question.
>>>> 
>>>> 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.
>>> 
>>> I don't think I understand the question.  The above already *is* real
>>> Haskell.  What is there to escape?
>>> 
>>>> I thought of providing a defautl-wrapper for some required prelude
>>>> functions (such as print) inside my interpreter but I wonder if
>>>> there are more elegant ways to co-loacate a DSL and Haskell without
>>>> falling back to being a normal library only.
>>> 
>>> I don't understand this sentence either.  Can you explain what you are
>>> trying to do in more detail?
>>> 
>>> -Brent
>> 
>> 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20121203/063f4b04/attachment.htm>


More information about the Haskell-Cafe mailing list