On 20/02/2012, at 12:11 PM, john skaller wrote:

> ////////////////////////////
> sthe_name : = "@" sthe_name =># "(Prefix)";

small white lie: you would need

syntax fred { sthe_name : = "@" sthe_name =># "(Prefix)"; }
open syntax fred;

in user code. Now more magic:

typedef ptrs = typesetof ( &int, @int );

body """
void pr (void *p) {
printf("%p\\n",p);
}
""";

proc pr: !ptrs = "pr($1);";
pr x;

This procedure will accept either &int or @int argument.
This saves doing a conversion.

Unfortunately, typesets don't work quite right with polymorphism,
I couldn't get this to work for arbitrary T.  Now we have a use case
I can look at how the compiler handles polymorphic constraints.

However consider we also want this:

fun id[T] : @T -> @T = "$1";
fun id[T] : &T -> &T = "$1";

This is a pain. We either have to use a typeclass, which is function specific,
or we have to define multiple overloads. This is because Felix has no subtyping.

In this case is we knew &T was a sort of subtype of @T we could say that in the
second case the return type and argument were covariant, and that should be
enough for the type to be restricted by the compiler.

BTW:  another typeset based extension to the type system
intrigues me:

        fun div: int  * (int - {0}) -> int; // division
        fun div(x:int, y:int):int where x!=0 => ...

There's some interesting theory here:  the function isn't total in the form

        fun div: int * int -> int

because of division by zero. But we can either subtract out the illegal 0 from
the domain as shown, or, make it a pre-condition .. which is exactly the same
thing OR we can ADD a value to the return type:

        fun div: int * int -> int + error;
        fun div: int * int -> opt[int] // same idea as above

This makes this div total, and the restriction to the int - {0} case is
also total. The transformation here is a standard category theory square.

match denom with
| 0 -> None
| _ -> Some (x/y)
endmatch

this is related to deref of null pointers (I think the pair of function is an 
adjoint).


--
john skaller
skal...@users.sourceforge.net





------------------------------------------------------------------------------
Try before you buy = See our experts in action!
The most comprehensive online learning library for Microsoft developers
is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3,
Metro Style Apps, more. Free future releases when you subscribe now!
http://p.sf.net/sfu/learndevnow-dev2
_______________________________________________
Felix-language mailing list
Felix-language@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/felix-language

Reply via email to