SERVING THE QUANTITATIVE FINANCE COMMUNITY

 
User avatar
chocolatemoney
Posts: 322
Joined: October 8th, 2008, 6:50 am

C# Quiz

November 25th, 2013, 3:00 pm

QuoteOriginally posted by: CuchulainnQuoteOriginally posted by: chocolatemoneyI think on my side the most annoying missing feature of .net (or F# in the specific) is the lack of higher kinded-types: http://cs.hubfs.net/topic/None/59392Can you give some examples? What are you trying to do exactly?Is Tuple such an example? // That F# code looks like Greek to me The idea is to work with types which abstract over types which abstract over types.One example (scala) could be:trait Functor [F[_]] { def map[A,B] (fn: A=>B)(fa: F[A]): F}this is like a type, which contains a box (for example a list, but we don't know yet), which contains something else - here of generic type A (input) and B (output).AFAIK, F# and (probl.) C# do not support this type of abstractions and you can not define, for example, a map function that takes any box and maps its content.This would be useful because I have values of different types organized in containers structures (the boxes). I am trying to write some code that could work for any type of box and any type of values in the box.
Last edited by chocolatemoney on November 24th, 2013, 11:00 pm, edited 1 time in total.
 
User avatar
Cuchulainn
Topic Author
Posts: 62608
Joined: July 16th, 2004, 7:38 am
Location: Amsterdam
Contact:

C# Quiz

November 25th, 2013, 4:31 pm

QuoteOriginally posted by: chocolatemoneyQuoteOriginally posted by: CuchulainnQuoteOriginally posted by: chocolatemoneyI think on my side the most annoying missing feature of .net (or F# in the specific) is the lack of higher kinded-types: http://cs.hubfs.net/topic/None/59392Can you give some examples? What are you trying to do exactly?Is Tuple such an example? // That F# code looks like Greek to me The idea is to work with types which abstract over types which abstract over types.One example (scala) could be:trait Functor [F[_]] { def map[A,B] (fn: A=>B)(fa: F[A]): F}this is like a type, which contains a box (for example a list, but we don't know yet), which contains something else - here of generic type A (input) and B (output).AFAIK, F# and (probl.) C# do not support this type of abstractions and you can not define, for example, a map function that takes any box and maps its content.This would be useful because I have values of different types organized in containers structures (the boxes). I am trying to write some code that could work for any type of box and any type of values in the box.What about late binding and dynamic type I suspect you are looking for template template parameter idea?? http://publib.boulder.ibm.com/infocente ... uments.htm
Last edited by Cuchulainn on November 24th, 2013, 11:00 pm, edited 1 time in total.
Step over the gap, not into it. Watch the space between platform and train.
http://www.datasimfinancial.com
http://www.datasim.nl
 
User avatar
chocolatemoney
Posts: 322
Joined: October 8th, 2008, 6:50 am

C# Quiz

November 26th, 2013, 7:52 am

QuoteOriginally posted by: CuchulainnQuoteOriginally posted by: chocolatemoneyQuoteOriginally posted by: CuchulainnQuoteOriginally posted by: chocolatemoneyI think on my side the most annoying missing feature of .net (or F# in the specific) is the lack of higher kinded-types: http://cs.hubfs.net/topic/None/59392Can you give some examples? What are you trying to do exactly?Is Tuple such an example? // That F# code looks like Greek to me The idea is to work with types which abstract over types which abstract over types.One example (scala) could be:trait Functor [F[_]] { def map[A,B] (fn: A=>B)(fa: F[A]): F}this is like a type, which contains a box (for example a list, but we don't know yet), which contains something else - here of generic type A (input) and B (output).AFAIK, F# and (probl.) C# do not support this type of abstractions and you can not define, for example, a map function that takes any box and maps its content.This would be useful because I have values of different types organized in containers structures (the boxes). I am trying to write some code that could work for any type of box and any type of values in the box.What about late binding and dynamic type I suspect you are looking for template template parameter idea?? http://publib.boulder.ibm.com/infocente ... nts.htmYes, thanks. The hacks above, in C# and C++ respectively would probably hack the problem. However:I refer to C# dynamic types as "hack" because they would bypass the type inference system, which is a very powerful tool.Re. template templates, I have to admit I have never worked with them. I am thinking how "The compiler will not consider any partial specialization even if their parameter lists match that of the template template parameter." would impact the way I'd write the library. Anyway, despite C++ power and speed, I decided to work in F#. For my personal needs, F# works great (http://fsharpforfunandprofit.com/posts/ ... ess-intro/)
 
User avatar
Cuchulainn
Topic Author
Posts: 62608
Joined: July 16th, 2004, 7:38 am
Location: Amsterdam
Contact:

C# Quiz

November 26th, 2013, 8:17 am

yeah, 'dynamic' is ugly, but the alternative is to use Reflection API to emit code
Last edited by Cuchulainn on November 25th, 2013, 11:00 pm, edited 1 time in total.
Step over the gap, not into it. Watch the space between platform and train.
http://www.datasimfinancial.com
http://www.datasim.nl
 
User avatar
Cuchulainn
Topic Author
Posts: 62608
Joined: July 16th, 2004, 7:38 am
Location: Amsterdam
Contact:

C# Quiz

November 26th, 2013, 10:04 am

Not sure if this helps, but you can use Reflection to create delegateshttp://msdn.microsoft.com/en-us/library/s3860fy3(v=vs.110).aspx
Step over the gap, not into it. Watch the space between platform and train.
http://www.datasimfinancial.com
http://www.datasim.nl
 
User avatar
chocolatemoney
Posts: 322
Joined: October 8th, 2008, 6:50 am

C# Quiz

November 27th, 2013, 8:00 am

Thanks for the link. It may go in the right direction; I guess I need to experiment
 
User avatar
Cuchulainn
Topic Author
Posts: 62608
Joined: July 16th, 2004, 7:38 am
Location: Amsterdam
Contact:

C# Quiz

November 27th, 2013, 8:14 am

QuoteOriginally posted by: chocolatemoneyThanks for the link. It may go in the right direction; I guess I need to experimentIf you can pose a scoped-down representative example and base the proof-of-concept on it?Do you want to emit code for data structures and/or algorithms?
Last edited by Cuchulainn on November 26th, 2013, 11:00 pm, edited 1 time in total.
Step over the gap, not into it. Watch the space between platform and train.
http://www.datasimfinancial.com
http://www.datasim.nl
 
User avatar
Cuchulainn
Topic Author
Posts: 62608
Joined: July 16th, 2004, 7:38 am
Location: Amsterdam
Contact:

C# Quiz

November 28th, 2013, 11:51 am

.NEt also has the option to create generic types etc. and put them in a dll.
Step over the gap, not into it. Watch the space between platform and train.
http://www.datasimfinancial.com
http://www.datasim.nl
 
User avatar
Cuchulainn
Topic Author
Posts: 62608
Joined: July 16th, 2004, 7:38 am
Location: Amsterdam
Contact:

C# Quiz

November 28th, 2013, 12:03 pm

Now I use the dll in another project and I can use the emitted class!
Step over the gap, not into it. Watch the space between platform and train.
http://www.datasimfinancial.com
http://www.datasim.nl
 
User avatar
chocolatemoney
Posts: 322
Joined: October 8th, 2008, 6:50 am

C# Quiz

December 4th, 2013, 6:12 pm

I have found a hack for my needs.I used this (http://www.nut-cracker.com.ar/index.php ... for-fsharp) as a starting point.Thanks for your posts: I am not working with C# but I have reconsidered reflection which before I thought it was the root of all evil.Very interesting stuff!
 
User avatar
Cuchulainn
Topic Author
Posts: 62608
Joined: July 16th, 2004, 7:38 am
Location: Amsterdam
Contact:

C# Quiz

December 4th, 2013, 6:57 pm

That's what I thought as well but I was being too narrow-mindedreflection, non s/w ex pattern
Last edited by Cuchulainn on December 3rd, 2013, 11:00 pm, edited 1 time in total.
Step over the gap, not into it. Watch the space between platform and train.
http://www.datasimfinancial.com
http://www.datasim.nl
 
User avatar
Polter
Posts: 2526
Joined: April 29th, 2008, 4:55 pm

C# Quiz

April 25th, 2014, 7:11 am

QuoteOriginally posted by: CuchulainnC# generics are different from C++ templates. Ideally I would prefer not to have to use dynamic (plan B is code emit...)Any good solutions?public class Wrong<T>{ //public static T add(T t1, T t2) {return t1 + t2;} // 1 public static T add(T t1, T t2) { return (dynamic) t1 + (dynamic) t2; } // 2}How about this: http://smellegantcode.wordpress.com/201 ... einterface IThing{ IThing Addition(IThing other); IThing Subtraction(IThing other);} static void Test<T>(T a, T b) where T : IThing{ var r1 = a + b; var r2 = a - b;}That works! Oh yes, you can do operators on generic parameter types. Couldn?t do that before.
 
User avatar
Cuchulainn
Topic Author
Posts: 62608
Joined: July 16th, 2004, 7:38 am
Location: Amsterdam
Contact:

C# Quiz

April 25th, 2014, 8:29 am

QuoteOriginally posted by: PolterQuoteOriginally posted by: CuchulainnC# generics are different from C++ templates. Ideally I would prefer not to have to use dynamic (plan B is code emit...)Any good solutions?public class Wrong<T>{ //public static T add(T t1, T t2) {return t1 + t2;} // 1 public static T add(T t1, T t2) { return (dynamic) t1 + (dynamic) t2; } // 2}How about this: http://smellegantcode.wordpress.com/201 ... einterface IThing{ IThing Addition(IThing other); IThing Subtraction(IThing other);} static void Test<T>(T a, T b) where T : IThing{ var r1 = a + b; var r2 = a - b;}That works! Oh yes, you can do operators on generic parameter types. Couldn?t do that before.Is there a C# equivalent of CRTP?
Step over the gap, not into it. Watch the space between platform and train.
http://www.datasimfinancial.com
http://www.datasim.nl
ABOUT WILMOTT

PW by JB

Wilmott.com has been "Serving the Quantitative Finance Community" since 2001. Continued...


Twitter LinkedIn Instagram

JOBS BOARD

JOBS BOARD

Looking for a quant job, risk, algo trading,...? Browse jobs here...


GZIP: On