On Wed, 2006-10-04 at 00:53 -0400, Peter Tanski wrote:
> On Oct 3, 2006, at 11:47 PM, skaller wrote:
> 
> > On Mon, 2006-10-02 at 09:40 -0400, Peter Tanski wrote:
> >
> >>> Typeclasses and instances have to be toplevel: that is,
> >>> they can be nested in modules but NOT in functions.
> >>
> >> It wouldn't make sense if typeclasses were nested in functions.
> >
> > Why not?
> >
> > They're allowed in programs .. and a program is just a function.
> 
> I knew you were going to say that :) 

Well of course you did .. that's why you made the original
assertion :)

>  Typeclasses exist to scope over  
> types and in a functional world types only make sense when they scope  
> over multiple functions.  If you had a single function with no nested  
> functions--the compiler may actually create nested functions, such as  
> the GNU extension to C, as a separate function anyway--defining a  
> type within the function for even a few procedures would not make any  
> real a difference.  

That's probably right.

> You can imagine the scenario: a typedef within a  
> function would really operate only as syntactic sugar since you would  
> have to (1) create the type and (2) destroy the type before returning  
> from the function itself. 


>  As a practical matter, in a language with  
> functional features and in any "functional" language function-nested  
> types would be very difficult (if not impossible) to support. 

That's funny because Felix *already* supports function nested types:

//------------------------------------------------------
#import <flx.flxh>

fun f(x:int)= {
  union x_t = | X of int;
  fun pr(a:x_t): int = {
    return
      match a with
      | X ?i => i
      | _ => 0
      endmatch
    ;
  }
  val a = X x;
  return a,the pr;
}

val v,d = f 1;

print$ d v; endl;
//-----------------------------------------------------

[This doesn't work in current SVN due to a bug I will shortly fix,
it does work on my box with the wrong code temporarily commented out]

-- 
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