Skip to content

Instantly share code, notes, and snippets.

@mxswd
Created December 21, 2013 09:27
Show Gist options
  • Save mxswd/8067259 to your computer and use it in GitHub Desktop.
Save mxswd/8067259 to your computer and use it in GitHub Desktop.
module Foo where
data Foo = Foo { name :: NSString, age :: NSNumber }
dothing :: Foo -> NSString
dothing x = do
n <- name x
a <- age x
return n
// FILE.h
#import <Foundation/Foundation.h>
@interface Foo : NSObject
@property (readonly, strong) NSString* name;
@property (readonly, strong) NSNumber* age;
- (id) __attribute__((unavailable)) init;
- (id)initFoo:(NSString*)name withAge:(NSNumber*)age;
+ (NSString*)dothing:(Foo*)x;
@end
// FILE.m
#import <Foundation/Foundation.h>
#import "test.h"
@implementation Foo
- (id)initFoo:(NSString*)name withAge:(NSNumber*)age
{
if (self = [super init]) {
_name = name;
_age = age;
return self;
} else
return nil;
}
+ (NSString*)dothing:(Foo*)x
{
id n = [x name];
id a = [x age];
return n;
}
@end
// run.m
#import "test.h"
int main() {
Foo *foo = [[Foo alloc] initFoo:@"max" withAge:@9001];
NSLog(@"%@", [Foo dothing:foo]);
return 0;
}
// ./a.out
// 2013-12-21 20:22:52.517 a.out[27828:303] max
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment