|
From: Judah J. <jud...@gm...> - 2008-04-06 20:34:38
|
On Sun, Apr 6, 2008 at 12:28 PM, Judah Jacobson
<jud...@gm...> wrote:
> On Sun, Apr 6, 2008 at 8:21 AM, Christopher St John <cks...@gm...> wrote:
> > I see that the project has moved to Google code, but I didn't any
> > mailing lists there, is this list still active? I'll give it a shot...
> >
> > I'm using HOC from the google code subversion repository on
> > OS X 10.4.11 with ghc 6.8.2. I'm running through some exercises
> > in the HIllegass Cocoa Programming book. I'm trying to create
> > a custom view that has a designated initializer like this:
> >
> > - (id)initWithFrame:(NSRect)rect
> > {
> > if( self = [super initWithFrame:rect] ) {
> > ...
> > }
> > return self;
> > }
> >
> > I have the class ("StetchView") implemented in Haskell, and,
> > with the exception of the initializer, it runs:
> >
> > $(declareClass "StretchView" "NSView")
> >
> > $(exportClass "StretchView" "sv_" [
> > InstanceVariable "path" [t| Maybe (NSBezierPath ()) |]
> > [| Nothing |],
> > InstanceMethod 'drawRect,
> > InstanceMethod 'initWithFrame,
> > InstanceMethod 'windowNibName
> > ])
> >
> > I've got the initializer looking like this (I was trying to cut
> > it down to the absolute minimum):
> >
> > sv_initWithFrame rect self = do
> > return self
> >
> > But that doesn't work, see below for what happens.
>
> I think you need the following (untested, but I confirmed that it typechecks):
>
>
> sv_initWithFrame rect self = do
> initWithFrame rect (super self)
> -- any other custom initialization code goes here
>
> Note that this corresponds to the call to [super initWithFrame:rect]
> in the Objective-C code you posted above.
>
> Hope that helps,
> -Judah
>
Sorry, I was wrong above. The correct code would be:
sv_initWithFrame rect self = do
self' <- fmap castObject $ initWithFrame rect (super self)
-- Run any custom initialization on self'
return self'
-Judah
|