On Sun, 2007-03-25 at 18:30 -0700, Erick Tryzelaar wrote:

> But we can't do this directly because we're providing two instance of 
> Show for tiny and utiny. So, rather than having to do this:
> 
> instance[t in typesetof(short,ushort,int,uint,...)] Show[t] { ... }

Well of course, you can repartition the typesets in the library.

> I'd prefer to do this:
> 
> instance[t in basic_types - typesetof(tiny,utiny)] Show[t] { ... }
> 
> But this doesn't work for me. Did I miss how to do this, or does it need 
> to be implemented?

It's not implemented. Typesets are a bit messy because *in theory*
the elements aren't types, but patterns, that is:

        t: t isin ts

actually means

        typematch t with
        | ts1 => 1
        | ts2 => 1
        | ... => 1
        | _ => 0
        endmatch

and that indeed is how it is implemented. The problem is that 
whilst subtraction of base types is clearly simple, it isn't
well defined for patterns in general: clearly

        t isin ts - ts'

could be defined by

        t isin ts and not (t isin ts')

but the problem is that ts-ts' is no longer a list of 
patterns. 

It is possible to develop a proper calculus of typesets I imagine,
but at the moment, the only operator allowed on them is 
a flattening union. (i.e a typeset of typesets is flattened).


> Also, think it'd be doable to have "open Show[basic_types]" instead of 
> having to list out each type?

Yes, that works now, except the syntax is:

open[t in basic_types] Show[t];

You should read his as:

for all t in basic_types open Show[t]

Any constraints are applied where the implicit quantifier lives,
this is the same as for instances, for example:

// equality for triples
instance[t,u,v with Eq[t], Eq[u], Eq[v]] Eq[t*u*v] {
  fun eq: (t * u * v) * (t * u * v) -> bool =
  | (?x1,?y1,?z1),(?x2,?y2,?z2) => x1==x2 and y1 == y2 and z1 == z2
  ;
}


> And just to repeat myself from the last time we talked about this, I'd 
> still like to be able to do "open instance Show[int]", even if it isn't 
> quite conceptually sound. I'd just make the code a bit easier to read :)

And again remember the reason not to: you can define helper
functions in instances. These functions are private to the
instance, open wouldn't make them accessible but it would
look like it.

Also, you can open ANY specialisation of a typeclass, it doesn't
have to match a visible instance (as long as an instance covers it).


-- 
John Skaller <skaller at users dot sf dot net>
Felix, successor to C++: http://felix.sf.net

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Felix-language mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/felix-language

Reply via email to