dsl

How can I handle operations over many different types in my DSL?

对着背影说爱祢 提交于 2019-12-10 07:36:59
问题 Suppose Haskell is to be used to implement an interpreter for a domain specific language. The DSL has a large number of type, represented as data constructors, and a large number of binary expressions. A naive first attempt would be a type class BinaryOps encapsulating all binary operations over MyType in the DSL: data MyType = A String | B Integer | C Bool | D Double {- | E .. Z -} class BinaryOps a where f :: a -> a -> a g :: a -> a -> a h :: a -> a -> a j :: a -> a -> a {- many more binary

How to get Kotlin's type safe builders to work in Scala?

情到浓时终转凉″ 提交于 2019-12-10 04:21:16
问题 Kotlin has awesome type safe builders that make possible to create dsl's like this html { head { title("The title") body {} // compile error } body {} // fine } Awesomeness is that you cannot put tags in invalid places, like body inside head, auto-completion also works properly. I'm interested if this can be achieved in Scala. How to get it? 回答1: If you are interested in building html, then there is a library scalatags that uses similar concept. Achieving this kind of builders does not need

Scala DSL: method chaining with parameterless methods

给你一囗甜甜゛ 提交于 2019-12-09 12:41:37
问题 i am creating a small scala DSL and running into the following problem to which i dont really have a solution. A small conceptual example of what i want to achieve: (Compute write "hello" read 'name calc() calc() write "hello" + 'name ) the code defining this dsl is roughly this: Object Compute extends Compute{ ... implicit def str2Message:Message = ... } class Compute{ def write(msg:Message):Compute = ... def read(s:Symbol):Compute = ... def calc():Compute = { ... } } Now the question: how

Working out the details of a type indexed free monad

不打扰是莪最后的温柔 提交于 2019-12-09 04:39:09
问题 I've been using a free monad to build a DSL. As part of the language, there is an input command, the goal is to reflect what types are expected by the input primitive at the type level for additional safety. For example, I want to be able to write the following program. concat :: Action '[String, String] () concat = do (x :: String) <- input (y :: String) <- input output $ x ++ " " ++ y Along with an evaluation function eval :: Action params res -> HList params -> [String] eval = ... Which

Groovy DSL: creating dynamic closures from Strings

人盡茶涼 提交于 2019-12-08 07:46:46
问题 There are some other questions on here that are similar but sufficiently different that I need to pose this as a fresh question: I have created an empty class, lets call it Test. It doesn't have any properties or methods. I then iterate through a map of key/value pairs, dynamically creating properties named for the key and containing the value... like so: def langMap = [:] langMap.put("Zero",0) langMap.put("One",1) langMap.put("Two",2) langMap.put("Three",3) langMap.put("Four",4) langMap.put(

Using a Scala symbol literal results in NoSuchMethod

血红的双手。 提交于 2019-12-08 01:08:33
问题 I have recently begun using Scala. I've written a DSL in it which can be used to describe a processing pipeline in medici. In my DSL, I've made use of symbols to signify an anchor, which can be used to put a fork (or a tee, if you prefer) in the pipeline. Here's a small sample program that runs correctly: object Test extends PipelineBuilder { connector("TCP") / Map("tcpProtocol" -> new DirectProtocol()) "tcp://localhost:4858" --> "ByteToStringProcessor" --> Symbol("hello") "stdio://in

Need to process multiple files in parallel in Spring Integration

你离开我真会死。 提交于 2019-12-07 13:41:35
问题 I have a SFTP directory and reading files and sending the files for further processing to a ServiceActivator.At any point I need to process them parallely using the handler. Here is my SPring Integration java DSL flow. IntegrationFlows.from(Sftp.inboundAdapter(getSftpSessionFactory()) .temporaryFileSuffix("COPY") .localDirectory(directory) .deleteRemoteFiles(false) .preserveTimestamp(true) .remoteDirectory("remoteDir")) .patternFilter("*.txt")), e -> e.poller(Pollers.fixedDelay(500)

Obtaining the client IP in Akka-http

不羁岁月 提交于 2019-12-07 05:47:47
问题 I am trying to write an Akka HTTP microservice (akka version 2.4.11, Scala version 2.11.8, both latest versions at time of writing) which is aware of the client service's IP (i.e., remote address), and I cannot get this to work. I can create and run a service which says 'Hello!' using a route like this: val routeHello: Route = path("SayHello") { get { entity(as[String]) { body => complete { HttpResponse(entity = HttpEntity("Hello!")) } } } } I have constructed a similar route to the one above

DSL block without argument in ruby

余生颓废 提交于 2019-12-06 23:13:00
问题 I'm writing a simple dsl in ruby. Few weeks ago I stumbled upon some blog post, which show how to transform code like: some_method argument do |book| book.some_method_on_book book.some_other_method_on_book :with => argument end into cleaner code: some_method argument do some_method_on_book some_other_method_on_book :with => argument end I can't remember how to do this and I'm not sure about downsides but cleaner syntax is tempting. Does anyone have a clue about this transformation? 回答1: def

DSL in scala using case classes

故事扮演 提交于 2019-12-06 21:10:58
问题 My use case has case classes something like case class Address(name:String,pincode:String){ override def toString =name +"=" +pincode } case class Department(name:String){ override def toString =name } case class emp(address:Address,department:Department) I want to create a DSL like below.Can anyone share the links about how to create a DSL and any suggestions to achieve the below. emp.withAddress("abc","12222").withDepartment("HR") Update: Actual use case class may have more fields close to