Created
December 21, 2013 09:27
-
-
Save mxswd/8067259 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Foo where | |
data Foo = Foo { name :: NSString, age :: NSNumber } | |
dothing :: Foo -> NSString | |
dothing x = do | |
n <- name x | |
a <- age x | |
return n |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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