digitalmars.D.learn - Pure and higher-order functions
- mist (11/11) Feb 23 2012 Hello!
- deadalnix (8/18) Feb 23 2012 Information is lost because of what f2 accept as a type. f2'q param
- mist (2/2) Feb 23 2012 But is there any way to actually say D compiler that I want this
- Jonathan M Davis (3/5) Feb 23 2012 Mark the delegate type that it accepts as pure.
- mist (7/7) Feb 24 2012 Ok, finally understood.
- bearophile (5/6) Feb 24 2012 I don't know. Maybe it's just a parser bug. There are some of those in B...
- mist (2/2) Feb 24 2012 Actually, looks like you have done it already 2 years ago :)
Hello! I have been asked few question recently from a Haskell programmer about D2 and, after experimenting a bit, have found that I really can't provide a good answe myself, as I am not getting a design limititations (if any). Here is the snippet, it is pretty self-descriptive: http://codepad.org/DBdCJYI2 Am i right, that all information about purity & Co is lost at runtime and there is no way to write pure-aware higher-order function using dynamic function pointers? That would have made me really sad :(
Feb 23 2012
Le 23/02/2012 21:00, mist a écrit :Hello! I have been asked few question recently from a Haskell programmer about D2 and, after experimenting a bit, have found that I really can't provide a good answe myself, as I am not getting a design limititations (if any). Here is the snippet, it is pretty self-descriptive: http://codepad.org/DBdCJYI2 Am i right, that all information about purity & Co is lost at runtime and there is no way to write pure-aware higher-order function using dynamic function pointers? That would have made me really sad :(Information is lost because of what f2 accept as a type. f2'q param isn't pure, so you gat what you except. Within f2, the fact that your function is pure is lost. f2 accept any function, pure or not. pure function can be casted automatically to non pure, because it is safe, but the other way around, it is impossible (because purity constraint would be broken).
Feb 23 2012
But is there any way to actually say D compiler that I want this function to accept only pure delegates?
Feb 23 2012
On Thursday, February 23, 2012 21:17:46 mist wrote:But is there any way to actually say D compiler that I want this function to accept only pure delegates?Mark the delegate type that it accepts as pure. - Jonathan M Davis
Feb 23 2012
Ok, finally understood. I was trying to declare hof like this: void f2( pure int function() param ) , similar to the way I declare usual pure functions. Looks like it is syntax error and only void f2( int function() pure param ) is allowed. That led me to false conclusion, that such signature is not allowed at all. Are there any reasons for this inconsistency?
Feb 24 2012
mist:Are there any reasons for this inconsistency?I don't know. Maybe it's just a parser bug. There are some of those in Bugzilla. If you don't like it, then I suggest you to add it to D Bugzilla. Bye, bearophile
Feb 24 2012
Actually, looks like you have done it already 2 years ago :) http://d.puremagic.com/issues/show_bug.cgi?id=4505
Feb 24 2012