-
-
Save jspahrsummers/3114225 to your computer and use it in GitHub Desktop.
mutableStringWithString :: Id -> IO Id | |
mutableStringWithString str = | |
getClass "NSMutableString" <.> stringWithString str | |
arrayWithObjects :: [Id] -> IO Id | |
arrayWithObjects objs = do | |
getClass "NSArray" <.> arrayWithObjectsAndCount objs (length objs) |
Ah, gotcha. You still won't be able to use (@)
as an alias for return
, since infix operators have to take two arguments.
And flip ($)
will work fine, because its function argument is partially applied; remember that function application binds tighter than infix operators. So, the following works:
(@.) = flip ($)
putFourStrings :: String -> String -> String -> String -> IO ()
putFourStrings a b c d = putStrLn a >> putStrLn b >> putStrLn c >> putStrLn d
"fourth" @. putFourStrings "first" "second" "third"
-- first
-- second
-- third
-- fourth
(In addition: the very fact that return x >>= f a b c
can do what you want it to indicates that x @. f a b c
can do the same. In fact, the two are provably equivalent).
Hmm, interesting. I'll make sure to add that. Thanks!
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?
Yep! But you don't need to make a new operator. It's called (>>=)
. ;-)
mutableStringWithString str =
getClass "NSMutableString" >>= stringWithString str
That appears to drop str
into the self
position of stringWithString
, though.
Nope. Remember, we're putting the receiver last.
You're right. Sorry, I've been hopping back and forth between a few different mental models today.
;) no worries
I'm talking about this case:
Unless I'm missing something,
flip ($)
can't do that.