dsl

Typed abstract syntax tree with function application

怎甘沉沦 提交于 2019-11-30 15:03:33
I am trying to write a typed abstract syntax tree datatype that can represent function application. So far I have type Expr<'a> = | Constant of 'a | Application of Expr<'b -> 'a> * Expr<'b> // error: The type parameter 'b' is not defined I don't think there is a way in F# to write something like 'for all b' on that last line - am I approaching this problem wrongly? In general, the F# type system is not expressive enough to (directly) define a typed abstract syntax tree as the one in your example. This can be done using generalized algebraic data types (GADTs) which are not supported in F#

Successful Domain-Specific Languages ? Which one do you use? [closed]

蹲街弑〆低调 提交于 2019-11-30 11:09:56
问题 As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. Closed 7 years ago . I'm interested in Domain Specific Languagess design and implementation. Much of the DSLs that I know stem from the academic world. Can

Interesting DSLs, Implemented in Scala? [closed]

柔情痞子 提交于 2019-11-30 11:08:00
问题 As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. Closed 6 years ago . I've seen BASIC and Apache Camel DSLs in Scala, and they're just fantastic. Any more examples of such DSLs? 回答1: You have a good

Writing my first DSL in C# and getting hung up on func<T> & Action

夙愿已清 提交于 2019-11-30 09:51:59
I'm taking a crack at writing my first DSL for a simple tool at work. I'm using the builder pattern to setup the complex parent object but am running into brick walls for building out the child collections of the parent object. Here's a sample: Use: var myMorningCoffee = Coffee.Make.WithCream().WithOuncesToServe(16); Sample with closure (I think that's what they're called): var myMorningCoffee = Coffee.Make.WithCream().PourIn( x => { x.ShotOfExpresso.AtTemperature(100); x.ShotOfExpresso.AtTemperature(100).OfPremiumType(); } ).WithOuncesToServe(16); Sample class (without the child PourIn()

Dynamically define named classes in Ruby

一笑奈何 提交于 2019-11-30 08:02:56
I am writing an internal DSL in Ruby. For this, I need to programmatically create named classes and nested classes. What is the best way to do so? I recon that there are two ways to do so: Use Class.new to create an anonymous class, then use define_method to add methods to it, and finally call const_set to add them as named constants to some namespace. Use some sort of eval I've tested the first way and it worked, but being new to Ruby, I am not sure that putting classes as constants is the right way. Are there other, better ways? If not, which of the above is preferable? If you want to create

Printing an AST with variable names

怎甘沉沦 提交于 2019-11-30 07:17:21
I am trying to implement an EDSL in Haskell. I would like to pretty print the AST with the variable names that are bound (if I can't get the real names then some generated names would do). This is how far I have got with a simple example: import Control.Monad.State data Free f a = Roll (f (Free f a)) | Pure a instance Functor f => Monad (Free f) where return = Pure (Pure a) >>= f = f a (Roll f) >>= g = Roll $ fmap (>>= g) f data Expr a = I a | Plus (Expr a) (Expr a) deriving (Show) data StackProgram a next = Pop (a -> next) | Push a next instance Functor (StackProgram a) where fmap f (Pop k) =

How to construct QueryBuilder from JSON DSL when using Java API in ElasticSearch?

此生再无相见时 提交于 2019-11-30 04:58:15
I'm using ElasticSearch as a search service in Spring Web project which using Transport Client to communicate with ES. I'm wondering if there exists a method which can construct a QueryBuilder from a JSON DSL. for example, convert this bool query DSL JSON to a QueryBuilder. { "query" : { "bool" : { "must" : { "match" : {"content" : "quick"}, "should": { "match": {"content" : "lazy"} } } } I need this method because I have to receive user's bool string input from web front-side, and parse this bool string to a QueryBuilder. However it not suit to use QueryBuilders.boolQuery().must(matchQB)

Understanding method_added for class methods

蓝咒 提交于 2019-11-30 03:22:20
I would like to do some magic in the moment instance and class methods are added to some class. Therefore I tried the following: module Magic def self.included(base) base.extend ClassMethods end module ClassMethods def method_added(name) puts "class method '#{name}' added" end def some_class_method puts "some class method" end end end class Foo include Magic def self.method_added(name) puts "instance method #{name} added" end end This approach works well for instance methods, fails for class methods. How can I solve that? Any suggestions? you are looking for singleton_method_added: module

Why can an instance of a class access private fields of another instance of its own type?

主宰稳场 提交于 2019-11-30 00:57:36
问题 An instance of a class, in Java, can access private fields of a different instance of its own type, such as in the following listing: public class Foo { private int secret; public void bar(final Foo foo) { foo.secret = 100; } } What would be the argument for such semantics (when designing a language)? 回答1: Well, first you have to ask "why have private fields at all?" Private fields are primarily for encapsulation: a user of a a class shouldn't have to know the internals of that class'

Successful Domain-Specific Languages ? Which one do you use? [closed]

旧城冷巷雨未停 提交于 2019-11-29 23:19:49
I'm interested in Domain Specific Languagess design and implementation. Much of the DSLs that I know stem from the academic world. Can you give me some pointers to DSLs that are actually used in the industry ? and that you use on a daily-basis...which are really convenient.. (I'm interested in declarative languages too, but not really xml-based ones...)... I'd like to establish a (non-exhaustive) list of industry-deployed languages...i know this is huge... Sometimes, I'm implementing using a General Purpose Language things that could be trivially done using a DSL. EDIT I'm mainly interested in