I am playing around with Felix to make "polymorphic variables" work.
In the simplest form you can do this: //// var x[T]: int = 1; println$ x[double]; // prints 1 //// i.e. you can index variables. And you can do this: //// var x[T]:T; x[int]=1; x[double]=1.2; println$ x[int], x[double]; //// Note you cannot do this: /// var x[T]:T; x[int]=1; x[double]=1.2; var y[T]:T = x[T]; // NO! /// You get: ~/felix>flx xy Client Error binding expression x[T] CLIENT ERROR [lookup_name_in_env]: Name 'T' not found in environment (depth 2) In ./xy.flx: line 5, cols 16 to 16 4: 5: var y[T]:T = x[T]; * 6: Of course, the compiler is right, to make this work, you'd have to assign y[int], y[double] when you assigned x .. and that's the job of a function. Ok .. so .. such polymorphic variables aren't really much use. But consider: ///// typeclass X[T] { const zzero:T = "(?1)1"; virtual const zzz:T; } instance[T] X[T] { val zzz = 42; } open[T] X[T]; println$ "Zero[int]=" + str zzz[int]; //// This currently fails. Polymorphic "const" works fine, because evaluation of the RHS C expression is delayed until the point of use. However currently Felix can't handle instantiation of the virtual const. This would be nice: typeclass FloatAddgrp[t] { inherit Eq[t]; virtual fun zero: unit -> t; virtual fun add: t * t -> t; virtual fun neg: t -> t; virtual fun sub(x:t,y:t):t => add (x,neg y); virtual proc pluseq (px:&t,y:t) { px <- *px + y; } virtual proc minuseq (px:&t,y:t) { px <- *px - y; } reduce id (x:t): x+zero() => x; reduce id (x:t): zero()+x => x; reduce inv(x:t): x-x => zero(); reduce inv(x:t): - (-x) => x; axiom sym (x:t,y:t): x+y == y+x; } Writing "zero()" instead of just zero here is a pain. In an instance: instance FloatAddgrp[int] { ... fun zero()=>0; } you have to define a function. To use it you have to write println$ 1 + zero(); or if you opened over a variable T println$ 1 + zero[int](); It would be nice to get rid of the () somehow. [AFAIK Haskell can do this] One trick to get around this might be to just define: #f means f() so you could write #zero #zero[int] The advantage of this trick is that it is just syntactic sugar. [Actually we could use *zero since functions aren't pointers, though this might get confusing with C functions hanging around .. ] Anyhow .. typeclasses (are supposed) to allow binding a virtual const to a const or val. -- john skaller skal...@users.sourceforge.net ------------------------------------------------------------------------------ Learn Windows Azure Live! Tuesday, Dec 13, 2011 Microsoft is holding a special Learn Windows Azure training event for developers. It will provide a great way to learn Windows Azure and what it provides. You can attend the event by watching it streamed LIVE online. Learn more at http://p.sf.net/sfu/ms-windowsazure _______________________________________________ Felix-language mailing list Felix-language@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/felix-language