Re[2]: The future of Haskell discussion

hw hw <>
Tue, 18 Sep 2001 10:23:43 +0300

Hello Yoann,

Monday, September 17, 2001, 7:12:42 PM, you wrote:

>> In the case of the Draw monad (which is identical to the
>> IO monad except that it carries a "device context" around as an
>>   setPicture window (withColor blue (withFont helvetica (text "Hello World")))

YP> you can achieve the same in many langage such as c++. 
YP> I dont really see what is haskell specific in your code.

YP> pseudo code (i dont remember exactly c++ :) ):
You made some mistakes here. ^^^^^^^^^^^^^^^

YP> class Draw {
YP>  Color color;
YP>  Font  font;
YP>  Widget wid;
YP>  Draw(Widget w) { wid = w }
YP>  draw(window) { Color old; Font old;  
YP>                 oldc = setColor color; oldf = setFont font; 
YP>                 wid.draw(window);
YP>                 setColor oldc; setFont oldf;
YP>                }  
YP>  withColor (Color c) {color = c}
You should always return references to 'this' in every method, which may
be used during "glued" calls, so:
  Draw& withColor (Color c) {color = c; return *this;}
  Draw& withFont  (Font f)  {font = f; return *this;}

It was one of the sources of resistance by B.Stroustrup to include "named"
parameters in function calls, for ex: withColor(c=blue) And the
technique shown was similar with mentioned above. I think that this is
a bit pervertive.

YP> new Draw(new textWidget("Hello World"))->withColor(blue)->withFont("helvetica")->draw(window)
YP> there are plenty of way to achieve what you do.
I just clarified some moments in shown C++ example. Not more.

Best regards,