On Sep 10, 2006, at 11:54 AM, skaller wrote:
> On Sun, 2006-09-10 at 11:10 -0400, Peter Tanski wrote:
>
>> Then create different kinds of vectors available:
>>
>> instance Vector[int] {
>> }
>>
>> instance Vector[float] {
>> }
>
> No, that's no good. Vector is polymorphic anyhow: we want
>
> typeclass[t] sequence[c[t]] ..
> instance[t] vector[t] ...
>
> If you like this instance is a 'partial specialisation' :)
You're right. Initially I created Vector as a type:
union Vector T = Vec array[T]
type Vector float = Vec float
and then created Vector as an instance of the CppContainer typeclass:
instance CppContainer (Vector T) {
}
-- the parenthesised form is both readable and kindable (Vector has
kind (* -> *), T has kind *)
Of course, abstracting the C++ container vector<> as a Felix array
would only create a Felix-version of vector, which you essentially
already have with list[T], and what you need the vector type for is
an interface to the C++ type. I thought that as a container Vector
would work best as a set of functions in Felix:
typeclass Vector[T] => CppSequence[T] {
fun default_ctor[T] unit -> x:T { } // default constructor
fun sz_e_ctor[T] (n:int, x:T) -> y:T { } // size n, with element x
fun sz_ctor[T] n:int -> x:T { } // size n, elements undefined
fun cp_ctor[T where Vector[T] ] x:T -> y:T { } // copy constructor
...
}
Then each of these typeclass functions would call out to C++ (you
could even specialise it to include your own allocator without
changing the interface).
It might work better with data types and functors:
union Vector T = Vec T
typeclass[T] CppSequenceFunctor[T] {
fun fmap[T where CppSequence[T]] (f:(T -> T),x:T) -> y:T { }
}
instance[T] CppSequenceFunctor[Vector T] {
fun map_sequence[T where CppSequence[T]] (f:(T -> T),x:T) -> y:T {
// match (Vec a), call out to C++ to apply function
}
}
// add the CppSequenceFunctor as one super-class of CppSequence:
typeclass[T] Vector[T] => (CppSequence[T], CppSequenceFunctor[T]) {
}
But this concept would be difficult for C++ programmers to grasp.
The best option would be to use modules with functions (Felix functors).
Notice that when you get a lot of brackets and 'where' statements
this syntax style rapidly becomes inscrutable. I am about one
keystroke away from going back to pure Haskell; speed is great but
this is a lot of work! I have to get some other projects finished
and then I can get to work on a real Felix parser...
>> Separating the types out linearly is much more readable:
>>
>> typeclass Vector T {
>> }
>
> Yes but
>
> vector t i
>
> is unkindable.
Why would you use
vector t i
instead of
vector (t * i) ?
(1) In general types should allow multiple parameters:
union NewType a b c d e =
| NT a b c d e
| NTT (a * b * c * d * e)
(NewType might be parseable as
NewType (a * b * c * d * e)
OR
NewType (a b c d e) )
(2) A full implementation of typeclasses should enable multiple
parameters:
typeclass CppContainerType T U V { }
(3) With parentheses you may even include type constructors:
instance CppContainer (Vector T) { }
>> Felix already has the single-quote '; what would you use the backtick
>> (`) for, other than to distinguish particular types, such as:
>
> You have savings in the bank don't you?
>
> There are no character constants .. could be used for that ..
>
> --
> John Skaller <skaller at users dot sf dot net>
> Felix, successor to C++: http://felix.sf.net
>
-------------------------------------------------------------------------
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