Skip to content

Instantly share code, notes, and snippets.

@jspahrsummers
Created July 15, 2012 01:15
Show Gist options
  • Save jspahrsummers/3114225 to your computer and use it in GitHub Desktop.
Save jspahrsummers/3114225 to your computer and use it in GitHub Desktop.
Hypothetical messaging primitive for Objective-Haskell
mutableStringWithString :: Id -> IO Id
mutableStringWithString str =
getClass "NSMutableString" <.> stringWithString str
arrayWithObjects :: [Id] -> IO Id
arrayWithObjects objs = do
getClass "NSArray" <.> arrayWithObjectsAndCount objs (length objs)
@jspahrsummers
Copy link
Author

So, this works for the example you gave, and for any Id -> … function, but it doesn't seem to work for IO Id -> …:

mutableStringWithString :: Id -> IO Id
mutableStringWithString str = (getClass "NSMutableString") @. stringWithString str

Is there some way to make an <@.> operator for lifting + applying + joining?

@jonsterling
Copy link

Yep! But you don't need to make a new operator. It's called (>>=). ;-)

mutableStringWithString str = 
    getClass "NSMutableString" >>= stringWithString str

@jspahrsummers
Copy link
Author

That appears to drop str into the self position of stringWithString, though.

@jonsterling
Copy link

Nope. Remember, we're putting the receiver last.

@jspahrsummers
Copy link
Author

You're right. Sorry, I've been hopping back and forth between a few different mental models today.

@jonsterling
Copy link

;) no worries

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment