On Sep 10, 2006, at 1:31 AM, skaller wrote:

> On Sun, 2006-09-10 at 00:50 -0400, Peter Tanski wrote:
>> On Sep 8, 2006, at 9:49 PM, skaller wrote:
>
>> Regarding C++ template type notation, why did you choose square
>> brackets for the list of predicates, instead of angle brackets?
>
> Because < and > are comparison operators?

'<' and '>' are comparison operators in C++ as well and in C++ they  
are used to mark template parameters.  It all depends on context.  Of  
course Felix's LALR parser may have an easier time with  
distinguishing the trailing ">>" as an embedded predicate list from  
">>" as the right-shift operator (Felix doesn't have a right-shift  
operator but you may want to use ">>" as a sequence operator).  The  
consequence of the C++ "maximum munch" parser, where trailing  
embedded template parameters need a space "vector<int, Allocator<T>  
 >" should have been done away with a long time ago.

>>> But -- and you must promise not to scream here -- the
>>> 'most important' use of typeclasses is actually to automate
>>> wrapping C++ types. In this case 'the whole point' is
>>> in the defaults:
>>>
>>> typeclass Iterator[i,t] {
>>>    proc advance: i = "++$1";
>>>    fun deref: i -> t = "*$1";
>>>    fun eq: i * i -> 2 = "$1==$2";
>>> }
>>>
>>> This is actually the very first thing I want to do :)
>>
>> That's a great way to start!  To clarify, you want to be able to
>> create a general typeclass with default definitions, then derive
>> instances of that typeclass for each C++ type you want to import to
>> Felix?
>
> Almost. Replace 'each C++ type' with 'each C++ template':
> for example and instance for vector<T> .. ONE instance
> statement, not one for vector<int> and another for
> vector<float>.

Easy!  Simply create a typeclass for vectors and make the Vector  
typeclass a sub-class of (at least) Cpp types:

typeclass Vector[T] => ForeignCppType[T]  {
}

Possibly CppTemplateType and CppContainerType as well:

(1)
typeclass CppTemplateType[T] => ForeignCppType[T] {
}
(2)
typeclass CppContainerType[T] => CppTemplateType[T] {
}
(3)
instance CppContainerType[Vector[T]] {
}

Then create different kinds of vectors available:

instance Vector[int] {
}

instance Vector[float] {
}

instance Vector[Pointer] {
-- in the instance declaration you set up how the functions over  
vectors of each type operate, just as you do with C++ templates
}

By the way, after reading through this list, you might have concluded  
(as I have) that the syntax:

typeclass Class[Types]

(with the type parameters in brackets) gets very hard to read.   
Separating the types out linearly is much more readable:

typeclass Vector T {
}

instance Vector float {
}


>>> and one is very tempted to rip off Haskell and allow
>>>
>>>     a `add` b
>>>
>>> if only we weren't so short of punctuation :)
>>
>> What punctuation does `add` cover?
>
> It uses up the last free quote mark, backtick (`)

Felix already has the single-quote '; what would you use the backtick  
(`) for, other than to distinguish particular types, such as:

fun f[T, T`] ?

(Of course, here a single quote is more appropriate, anyway and may  
be parsed based on context; i.e., no quotes are allowed in predicate  
lists and quoted types only take double quotes ("), so quotes in  
predicate lists or attached to types are part of the type name.  I  
will admit such single-quotes would be difficult to pass around as  
strings because they would have to be backslash-escaped.)

-Pete


-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Felix-language mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/felix-language

Reply via email to