- About Scala
- Documentation
- Code Examples
- Software
- Scala Developers
domain language via dropping of "obj => import obj._" ?
Wed, 2009-03-25, 12:39
Hi,
I am just looking for a way to embed a domain specific language into Scala.
I checked out Monads and the other features of Scala, and while they are
great!, it seems they are not exactly what I am looking for. I will describe
my problem, and maybe someone could comment on how best to approximate this
in Scala.
let's say I have a class Context (and also a class theorem), and for example
the following methods (note that my notation might be a little bit off as I
am more used to SML than Scala):
Context.contra : String => (Context => theorem) => theorem
Context.theorem : theorem
Context.branch : theorem => (Context => theorem) => (Context => theorem) =>
theorem
I think the following code (or something close to it ) is possible in Scala
:
val c = someContext
val th = someTheorem
c.contra "A" {
d =>
d.branch th
{ e => e.theorem }
{ e => e.theorem }
}
I think I can rewrite the above code as follows:
val c = someContext
val th = someTheorem
c.contra "A" {
d => import d._
branch th
{ e => import e._ ; theorem }
{ e => import e._; theorem }
}
Now, it would be awesome if there would be a notation to drop the
"obj => import obj._", for example by replacing "{" with "{:" or something
like that. This would result in:
val c = someContext
val th = someTheorem
c.contra "A" {:
branch th {: theorem } {: theorem }
}
Is there a way of achieving something like that in Scala ?
Cheers,
Steven
Wed, 2009-03-25, 13:07
#2
Re: domain language via dropping of "obj => import obj._" ?
This already looks like a very good approximation that I didn't think of! The
only problem I see is that I might want to use the implicit argument several
times, for example I dont see how to translate
c.contra "A" {
d =>
d.branch d.theorem
{ e => e.theorem }
{ e => e.theorem }
}
equally easily with the "_." notation. With the "{:" notation:
c.contra "A" {:
branch theorem {: theorem } {: theorem }
}
Is there a preprocessor for Scala :-)
val c = someContext
val th = someTheorem
c.contra "A" (_.branch th (_.theorem) (_.theorem))
Wed, 2009-03-25, 13:17
#3
Re: domain language via dropping of "obj => import obj._" ?
On Wed, Mar 25, 2009 at 1:01 PM, Steven Obua <obua@me.com> wrote:
This already looks like a very good approximation that I didn't think of! The
only problem I see is that I might want to use the implicit argument several
times, for example I dont see how to translate
Put is as a curried implicit parameter?
c.contra "A" {
d =>
d.branch d.theorem
{ e => e.theorem }
{ e => e.theorem }
}
equally easily with the "_." notation. With the "{:" notation:
c.contra "A" {:
branch theorem {: theorem } {: theorem }
}
Is there a preprocessor for Scala :-)
val c = someContext
val th = someTheorem
c.contra "A" (_.branch th (_.theorem) (_.theorem))
--
View this message in context: http://www.nabble.com/domain-language-via-dropping-of-%22obj-%3D%3E-import-obj._%22---tp22699830p22700214.html
Sent from the Scala mailing list archive at Nabble.com.
--
Viktor Klang
Senior Systems Analyst
Wed, 2009-03-25, 13:17
#4
Re: domain language via dropping of "obj => import obj._" ?
"Put is as a curried implicit parameter?"
Anyone else thinking "Put him in the curry"?
2009/3/25 Viktor Klang :
>
>
> On Wed, Mar 25, 2009 at 1:01 PM, Steven Obua wrote:
>>
>> This already looks like a very good approximation that I didn't think of!
>> The
>> only problem I see is that I might want to use the implicit argument
>> several
>> times, for example I dont see how to translate
>
> Put is as a curried implicit parameter?
>
>>
>> c.contra "A" {
>> d =>
>> d.branch d.theorem
>> { e => e.theorem }
>> { e => e.theorem }
>> }
>>
>> equally easily with the "_." notation. With the "{:" notation:
>>
>> c.contra "A" {:
>> branch theorem {: theorem } {: theorem }
>> }
>>
>> Is there a preprocessor for Scala :-)
>>
>>
>> val c = someContext
>> val th = someTheorem
>>
>> c.contra "A" (_.branch th (_.theorem) (_.theorem))
>>
>>
>> --
>> View this message in context:
>> http://www.nabble.com/domain-language-via-dropping-of-%22obj-%3D%3E-impo...
>> Sent from the Scala mailing list archive at Nabble.com.
>>
>
>
>
> --
> Viktor Klang
> Senior Systems Analyst
>
Wed, 2009-03-25, 13:27
#5
Re: domain language via dropping of "obj => import obj._" ?
Well, what you showed isn't Scala. d.branch d.theorem would require a
method to have the name d.theorem. But I get the point.
c.contra "A" (_.branch foo _.theorem (_.theorem) (_.theorem)) could
work, with a sneaky implicit def from Function2 to Function1.
Oh, I'm about to get bashed for this.
2009/3/25 Steven Obua :
>
> This already looks like a very good approximation that I didn't think of! The
> only problem I see is that I might want to use the implicit argument several
> times, for example I dont see how to translate
>
> c.contra "A" {
> d =>
> d.branch d.theorem
> { e => e.theorem }
> { e => e.theorem }
> }
>
> equally easily with the "_." notation. With the "{:" notation:
>
> c.contra "A" {:
> branch theorem {: theorem } {: theorem }
> }
>
> Is there a preprocessor for Scala :-)
>
>
> val c = someContext
> val th = someTheorem
>
> c.contra "A" (_.branch th (_.theorem) (_.theorem))
>
>
> --
> View this message in context: http://www.nabble.com/domain-language-via-dropping-of-%22obj-%3D%3E-impo...
> Sent from the Scala mailing list archive at Nabble.com.
>
>
Wed, 2009-03-25, 13:37
#6
Re: domain language via dropping of "obj => import obj._" ?
On Wed, Mar 25, 2009 at 1:13 PM, Ricky Clarkson <ricky.clarkson@gmail.com> wrote:
"Put is as a curried implicit parameter?"
Anyone else thinking "Put him in the curry"?
http://www.youtube.com/watch?v=C0n88tZQc4Q ??? (first hit on Le Google...)
2009/3/25 Viktor Klang <viktor.klang@gmail.com>:
>
>
> On Wed, Mar 25, 2009 at 1:01 PM, Steven Obua <obua@me.com> wrote:
>>
>> This already looks like a very good approximation that I didn't think of!
>> The
>> only problem I see is that I might want to use the implicit argument
>> several
>> times, for example I dont see how to translate
>
> Put is as a curried implicit parameter?
>
>>
>> c.contra "A" {
>> d =>
>> d.branch d.theorem
>> { e => e.theorem }
>> { e => e.theorem }
>> }
>>
>> equally easily with the "_." notation. With the "{:" notation:
>>
>> c.contra "A" {:
>> branch theorem {: theorem } {: theorem }
>> }
>>
>> Is there a preprocessor for Scala :-)
>>
>>
>> val c = someContext
>> val th = someTheorem
>>
>> c.contra "A" (_.branch th (_.theorem) (_.theorem))
>>
>>
>> --
>> View this message in context:
>> http://www.nabble.com/domain-language-via-dropping-of-%22obj-%3D%3E-import-obj._%22---tp22699830p22700214.html
>> Sent from the Scala mailing list archive at Nabble.com.
>>
>
>
>
> --
> Viktor Klang
> Senior Systems Analyst
>
--
Viktor Klang
Senior Systems Analyst
Wed, 2009-03-25, 13:47
#7
Re: domain language via dropping of "obj => import obj._" ?
That's the one.
2009/3/25 Viktor Klang :
>
>
> On Wed, Mar 25, 2009 at 1:13 PM, Ricky Clarkson
> wrote:
>>
>> "Put is as a curried implicit parameter?"
>>
>> Anyone else thinking "Put him in the curry"?
>
> http://www.youtube.com/watch?v=C0n88tZQc4Q ??? (first hit on Le Google...)
>
>>
>> 2009/3/25 Viktor Klang :
>> >
>> >
>> > On Wed, Mar 25, 2009 at 1:01 PM, Steven Obua wrote:
>> >>
>> >> This already looks like a very good approximation that I didn't think
>> >> of!
>> >> The
>> >> only problem I see is that I might want to use the implicit argument
>> >> several
>> >> times, for example I dont see how to translate
>> >
>> > Put is as a curried implicit parameter?
>> >
>> >>
>> >> c.contra "A" {
>> >> d =>
>> >> d.branch d.theorem
>> >> { e => e.theorem }
>> >> { e => e.theorem }
>> >> }
>> >>
>> >> equally easily with the "_." notation. With the "{:" notation:
>> >>
>> >> c.contra "A" {:
>> >> branch theorem {: theorem } {: theorem }
>> >> }
>> >>
>> >> Is there a preprocessor for Scala :-)
>> >>
>> >>
>> >> val c = someContext
>> >> val th = someTheorem
>> >>
>> >> c.contra "A" (_.branch th (_.theorem) (_.theorem))
>> >>
>> >>
>> >> --
>> >> View this message in context:
>> >>
>> >> http://www.nabble.com/domain-language-via-dropping-of-%22obj-%3D%3E-impo...
>> >> Sent from the Scala mailing list archive at Nabble.com.
>> >>
>> >
>> >
>> >
>> > --
>> > Viktor Klang
>> > Senior Systems Analyst
>> >
>
>
>
> --
> Viktor Klang
> Senior Systems Analyst
>
Wed, 2009-03-25, 13:57
#8
Re: domain language via dropping of "obj => import obj._" ?
Exterminate!
Wed, 2009-03-25, 14:27
#9
Re: domain language via dropping of "obj => import obj._" ?
hmmh, I just looked into what implicit parameters are, and it seems to me one
should remove the "implicit parameters" feature from Scala and put in the
"{:" feature instead ;-)
Steven
> Put is as a curried implicit parameter?
Wed, 2009-03-25, 14:47
#10
Re: domain language via dropping of "obj => import obj._" ?
2009/3/25 Steven Obua :
>
> hmmh, I just looked into what implicit parameters are, and it seems to me one
> should remove the "implicit parameters" feature from Scala and put in the
> "{:" feature instead ;-)
That's because you don't understand them. :-)
Wed, 2009-03-25, 15:07
#11
Re: domain language via dropping of "obj => import obj._" ?
My "looking into" consisted of reading your article :-)
But I glanced only over the article, so you are right, I probably don't
understand them implicit args yet.
Could you give any advice on how to use implicit args for my purpose, this
would be great!
David MacIver wrote:
>
>> hmmh, I just looked into what implicit parameters are, and it seems to me
>> one
>> should remove the "implicit parameters" feature from Scala and put in the
>> "{:" feature instead ;-)
>
>> That's because you don't understand them. :-)
>
>
Wed, 2009-03-25, 17:27
#12
Re: domain language via dropping of "obj => import obj._" ?
Steve,
Other people on this thread have given you alternatives.
Before spending a lot of time writing up a SIP, I'd suggest that you look through the Scala archives. It's very rare that syntax changes that are neither shortcuts or in any other way give benefits are made to Scala. Speaking for myself, I think the proposal has no positives and a whole lot of negatives (syntactically ugly, enhances the "Scala as line noise" complaint, etc.)
So, you can choose to spend your time how you want, but I think the likelihood of success with a SIP is not high.
Thanks,
David
On Wed, Mar 25, 2009 at 4:39 AM, Steven Obua <obua@me.com> wrote:
--
Lift, the simply functional web framework http://liftweb.net
Beginning Scala http://www.apress.com/book/view/1430219890
Follow me: http://twitter.com/dpp
Git some: http://github.com/dpp
Other people on this thread have given you alternatives.
Before spending a lot of time writing up a SIP, I'd suggest that you look through the Scala archives. It's very rare that syntax changes that are neither shortcuts or in any other way give benefits are made to Scala. Speaking for myself, I think the proposal has no positives and a whole lot of negatives (syntactically ugly, enhances the "Scala as line noise" complaint, etc.)
So, you can choose to spend your time how you want, but I think the likelihood of success with a SIP is not high.
Thanks,
David
On Wed, Mar 25, 2009 at 4:39 AM, Steven Obua <obua@me.com> wrote:
Hi,
I am just looking for a way to embed a domain specific language into Scala.
I checked out Monads and the other features of Scala, and while they are
great!, it seems they are not exactly what I am looking for. I will describe
my problem, and maybe someone could comment on how best to approximate this
in Scala.
let's say I have a class Context (and also a class theorem), and for example
the following methods (note that my notation might be a little bit off as I
am more used to SML than Scala):
Context.contra : String => (Context => theorem) => theorem
Context.theorem : theorem
Context.branch : theorem => (Context => theorem) => (Context => theorem) =>
theorem
I think the following code (or something close to it ) is possible in Scala
:
val c = someContext
val th = someTheorem
c.contra "A" {
d =>
d.branch th
{ e => e.theorem }
{ e => e.theorem }
}
I think I can rewrite the above code as follows:
val c = someContext
val th = someTheorem
c.contra "A" {
d => import d._
branch th
{ e => import e._ ; theorem }
{ e => import e._; theorem }
}
Now, it would be awesome if there would be a notation to drop the
"obj => import obj._", for example by replacing "{" with "{:" or something
like that. This would result in:
val c = someContext
val th = someTheorem
c.contra "A" {:
branch th {: theorem } {: theorem }
}
Is there a way of achieving something like that in Scala ?
Cheers,
Steven
--
View this message in context: http://www.nabble.com/domain-language-via-dropping-of-%22obj-%3D%3E-import-obj._%22---tp22699830p22699830.html
Sent from the Scala mailing list archive at Nabble.com.
--
Lift, the simply functional web framework http://liftweb.net
Beginning Scala http://www.apress.com/book/view/1430219890
Follow me: http://twitter.com/dpp
Git some: http://github.com/dpp
Wed, 2009-03-25, 17:37
#13
Re: domain language via dropping of "obj => import obj._" ?
2009/3/25 Steven Obua :
>
>
> My "looking into" consisted of reading your article :-)
I somewhat regret that article. It appears to be widely misunderstood.
> But I glanced only over the article, so you are right, I probably don't
> understand them implicit args yet.
>
> Could you give any advice on how to use implicit args for my purpose, this
> would be great!
I cannot, as your purpose is not what they are for.
Wed, 2009-03-25, 17:47
#14
Re: domain language via dropping of "obj => import obj._" ?
While Steven's syntax may not be kosher with Scala's current syntax, I think there's a need here. This style of method injection into a block has become fairly popular and it does make writing DSLs easier and using them more pleasant. I think the approach has benefits and is better than the "state of the art" (ref. actors library using a global object and thread-local hacks)
I'm not sure what is the best solution but I think it's worth discussing until we get to something satisfactory.
I'll second your suggestion to scan the scala archives first. This has been brought up many times in different forms, including pre-SIPs (http://drmaciver.com/ImportSIP.html).
alex
2009/3/25 David Pollak <feeder.of.the.bears@gmail.com>
I'm not sure what is the best solution but I think it's worth discussing until we get to something satisfactory.
I'll second your suggestion to scan the scala archives first. This has been brought up many times in different forms, including pre-SIPs (http://drmaciver.com/ImportSIP.html).
alex
2009/3/25 David Pollak <feeder.of.the.bears@gmail.com>
Steve,
Other people on this thread have given you alternatives.
Before spending a lot of time writing up a SIP, I'd suggest that you look through the Scala archives. It's very rare that syntax changes that are neither shortcuts or in any other way give benefits are made to Scala. Speaking for myself, I think the proposal has no positives and a whole lot of negatives (syntactically ugly, enhances the "Scala as line noise" complaint, etc.)
So, you can choose to spend your time how you want, but I think the likelihood of success with a SIP is not high.
Thanks,
David
On Wed, Mar 25, 2009 at 4:39 AM, Steven Obua <obua@me.com> wrote:
Hi,
I am just looking for a way to embed a domain specific language into Scala.
I checked out Monads and the other features of Scala, and while they are
great!, it seems they are not exactly what I am looking for. I will describe
my problem, and maybe someone could comment on how best to approximate this
in Scala.
let's say I have a class Context (and also a class theorem), and for example
the following methods (note that my notation might be a little bit off as I
am more used to SML than Scala):
Context.contra : String => (Context => theorem) => theorem
Context.theorem : theorem
Context.branch : theorem => (Context => theorem) => (Context => theorem) =>
theorem
I think the following code (or something close to it ) is possible in Scala
:
val c = someContext
val th = someTheorem
c.contra "A" {
d =>
d.branch th
{ e => e.theorem }
{ e => e.theorem }
}
I think I can rewrite the above code as follows:
val c = someContext
val th = someTheorem
c.contra "A" {
d => import d._
branch th
{ e => import e._ ; theorem }
{ e => import e._; theorem }
}
Now, it would be awesome if there would be a notation to drop the
"obj => import obj._", for example by replacing "{" with "{:" or something
like that. This would result in:
val c = someContext
val th = someTheorem
c.contra "A" {:
branch th {: theorem } {: theorem }
}
Is there a way of achieving something like that in Scala ?
Cheers,
Steven
--
View this message in context: http://www.nabble.com/domain-language-via-dropping-of-%22obj-%3D%3E-import-obj._%22---tp22699830p22699830.html
Sent from the Scala mailing list archive at Nabble.com.
--
Lift, the simply functional web framework http://liftweb.net
Beginning Scala http://www.apress.com/book/view/1430219890
Follow me: http://twitter.com/dpp
Git some: http://github.com/dpp
Wed, 2009-03-25, 17:54
#15
Re: domain language via dropping of "obj => import obj._" ?
Hmmh, I don't think it is so ugly. And it leads to much shorter code. And
it allows for better DSLs. And it should be easy to implement. Actually, I
only see pros and no cons at all :-D
It should also lead to no backwards compatibility issues, and if people dont
need it, they won't notice it.
If you look at the thread, you can see that there are actually no true
alternatives. At least not as far as I can see.
So I'll give it a try anyway, because for my purposes this syntax would make
a big difference. If nobody likes it, well, at least I tried :-)
Cheers,
Steven
David Pollak-4 wrote:
>
> Steve,
>
> Other people on this thread have given you alternatives.
>
> Before spending a lot of time writing up a SIP, I'd suggest that you look
> through the Scala archives. It's very rare that syntax changes that are
> neither shortcuts or in any other way give benefits are made to Scala.
> Speaking for myself, I think the proposal has no positives and a whole lot
> of negatives (syntactically ugly, enhances the "Scala as line noise"
> complaint, etc.)
>
> So, you can choose to spend your time how you want, but I think the
> likelihood of success with a SIP is not high.
>
Wed, 2009-03-25, 17:57
#16
Re: domain language via dropping of "obj => import obj._" ?
2009/3/25 Alex Boisvert :
> While Steven's syntax may not be kosher with Scala's current syntax, I think
> there's a need here. This style of method injection into a block has
> become fairly popular and it does make writing DSLs easier and using them
> more pleasant. I think the approach has benefits and is better than the
> "state of the art" (ref. actors library using a global object and
> thread-local hacks)
Yes, I agree there's a need here. I'm not objecting to the proposal.
But the notion that is somehow should "replace" implicit arguments is
ludicrously misguided.
> I'm not sure what is the best solution but I think it's worth discussing
> until we get to something satisfactory.
>
> I'll second your suggestion to scan the scala archives first. This has been
> brought up many times in different forms, including pre-SIPs
> (http://drmaciver.com/ImportSIP.html).
Note that that SIP was submitted and rejected.
Wed, 2009-03-25, 18:17
#17
Re: domain language via dropping of "obj => import obj._" ?
val c = someContext
val th = someTheorem
new Lemma(c.contra("A")) {
branch(th) (_.theorem) (_.theorem)
}
Lemma's almost certainly the wrong word, I have not considered the
domain, but I needed an extra identifier.
> val c = someContext
> val th = someTheorem
>
> c.contra "A" {
> d =>
> d.branch th
> { e => e.theorem }
> { e => e.theorem }
> }
>
> I think I can rewrite the above code as follows:
>
> val c = someContext
> val th = someTheorem
>
> c.contra "A" {
> d => import d._
> branch th
> { e => import e._ ; theorem }
> { e => import e._; theorem }
> }
>
> Now, it would be awesome if there would be a notation to drop the
> "obj => import obj._", for example by replacing "{" with "{:" or something
> like that. This would result in:
>
> val c = someContext
> val th = someTheorem
>
> c.contra "A" {:
> branch th {: theorem } {: theorem }
> }
>
> Is there a way of achieving something like that in Scala ?
>
> Cheers,
>
> Steven
>
>
>
>
>
> --
> View this message in context: http://www.nabble.com/domain-language-via-dropping-of-%22obj-%3D%3E-impo...
> Sent from the Scala mailing list archive at Nabble.com.
>
>
Thu, 2009-03-26, 11:17
#18
Re: domain language via dropping of "obj => import obj._" ?
val c = someContext
val th = someTheorem
c.contra "A" (_.branch th (_.theorem) (_.theorem))
> val c = someContext
> val th = someTheorem
>
> c.contra "A" {
> d =>
> d.branch th
> { e => e.theorem }
> { e => e.theorem }
> }
>
> I think I can rewrite the above code as follows:
>
> val c = someContext
> val th = someTheorem
>
> c.contra "A" {
> d => import d._
> branch th
> { e => import e._ ; theorem }
> { e => import e._; theorem }
> }
>
> Now, it would be awesome if there would be a notation to drop the
> "obj => import obj._", for example by replacing "{" with "{:" or something
> like that. This would result in:
>
> val c = someContext
> val th = someTheorem
>
> c.contra "A" {:
> branch th {: theorem } {: theorem }
> }
>
> Is there a way of achieving something like that in Scala ?
>
> Cheers,
>
> Steven
>
>
>
>
>
> --
> View this message in context: http://www.nabble.com/domain-language-via-dropping-of-%22obj-%3D%3E-impo...
> Sent from the Scala mailing list archive at Nabble.com.
>
>