This one's odd. I don't think felix is expanding (1.0l / 1.0l):

#############################################
#import <flx.flxh>

typeclass Show2[T] {
  virtual fun str2: T -> string;
}

gen vsprintf[t]: string * t -> string = 
"flx::rtl::strutil::flx_asprintf(const_cast<char*>($1.c_str()),$T2)" 
requires flx_strutil;

fun format_real (t:ldouble, precision:int) : string = {
  var format = f"%%.%ig" precision;
  val s = vsprintf (format, t);
  return s;
}

instance Show2[ldouble] {
  fun str2  (t:ldouble) : string => format_real (t, 12);
}
open Show2[ldouble];

proc p[T with Show2[T]] (t:T) {
  print $ "str:  " + (str2 t); endl;
}

p (1.0l / 1.0l);
#############################################

error:

foo2.cpp: In function 'void 
flxusr::foo2::_init_(flxusr::foo2::thread_frame_t*)':
foo2.cpp:38: error: no match for 'operator/' in 
'flx::rtl::strutil::flx_asprintf(char*, ...)(1.0e+0l) / 1.0e+0l'
compilation terminated due to -Wfatal-errors.


but if you swap everything to double and to (1.0/1.0), it works:

#############################################
#import <flx.flxh>

typeclass Show2[T] {
  virtual fun str2: T -> string;
}

gen vsprintf[t]: string * t -> string = 
"flx::rtl::strutil::flx_asprintf(const_cast<char*>($1.c_str()),$T2)" 
requires flx_strutil;

fun format_real (t:double, precision:int) : string = {
  var format = f"%%.%ig" precision;
  val s = vsprintf (format, t);
  return s;
}

instance Show2[double] {
  fun str2  (t:double) : string => format_real (t, 12);
}
open Show2[double];

proc p[T with Show2[T]] (t:T) {
  print $ "str:  " + (str2 t); endl;
}

p (1.0 / 1.0);
#############################################


-------------------------------------------------------------------------
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
Felix-language@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/felix-language

Reply via email to