On 26/04/2012, at 3:21 AM, Raoul Duke wrote:

> seems like the kind of thing you can't get right from the get-go?

Not enough use cases to generalise.

> trying to figure out, as it sounds like you are doing, a flexible
> layout for things so that it can be externalized in libraries and so
> that people can revamp them over time to improve things, that would be
> a nice ground to gain?

There are two, separate, issues: file layout and types.
>  how does java do it? does it
> just avoid offering too many useful apis? :-)

Who cares what crud like Java does?
Java barely has a type system compared to Felix.
[Java provides JNI ... enough said ..]

More interesting, what does C++ do?
Ans: it provides ISO Standard interfaces in namespace std,
without stopping you using native C API. It provides UGLY
conditional compilation, and there's provision to use templates
and type traits if you want (though I've not heard of anyone
doing this).

It seems this works:

///////////////////////////////////
// The abstraction, with all the types required
// as parameters, in this case
// os: a phantom type for the os
// u: some os specific type (eg stat_t, fd_t)

class A[os,u] {
  virtual fun vf:u -> string;
  fun tw(a:u) => "xx " + vf a + " xx";
}

// Now, here's the Windows version
type win = "";
class W {

  // windows specific type and functions
  type st = "int";
  ctor int : st = "$1"; 
  ctor st : int = "$1";

  inherit A[win,st]; // grab the abstraction, viewed for Windows

  instance A[win,st] {   // implement the Windows view
    fun vf (x:st) => x.int.str+"w";
  }
}

// ditto for Posix
type pos = "";
class P {
  type st = "int";
  ctor int : st = "$1";
  ctor st : int = "$1";
  inherit A[pos,st];
  instance A[pos,st] {
    fun vf (x:st) => x.int.str+"p";
  }
}

open W;  // Make Windows the default
var x = st 42;
println$ tw x;

var y = P::st 42; // we can still use the Posix version
println$ P::tw y;
/////////////////////////////////////
~/felix>flx a
xx 42w xx
xx 42p xx
/////////////////////////////////

--
john skaller
skal...@users.sourceforge.net
http://felix-lang.org




------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
Felix-language mailing list
Felix-language@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/felix-language

Reply via email to